Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved [QT 5.8.0-1] How to make the QML Button is active (has focus) when application opens window

    QML and Qt Quick
    1
    2
    1553
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AnatolyS
      AnatolyS last edited by

      Hello!

      I have simple example:

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      ApplicationWindow {
          id: window
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          FocusScope {
              id: focusScope
              anchors.fill: parent
              anchors.margins: 40
              ColumnLayout {
                  anchors.fill: parent
                 Button {
                     id: button
                     focus: true
                     text: "PRESS 1"
                     Layout.fillWidth: true
                     Layout.fillHeight: true
                 }
                 Button {
                     text: "PRESS 2"
                     Layout.fillWidth: true
                     Layout.fillHeight: true
                 }
              }
          }
      }
      

      Running this code I guess that the first button get focus and this button shows active focus rectange. But actually the first button does not show active focus rectangle:
      alt problem

      Only when I press TAB, it becomes active:
      alt expectation

      Any hints?

      AnatolyS 1 Reply Last reply Reply Quote 0
      • AnatolyS
        AnatolyS @AnatolyS last edited by

        The problem is solved by @jpnurmi from the #qt-quick irc channel:

        button.forceActiveFocus(Qt.TabFocus)
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post