Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [QT 5.8.0-1] How to make the QML Button is active (has focus) when application opens window

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 1.9k Views
  • 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.
  • AnatolySA Offline
    AnatolySA Offline
    AnatolyS
    wrote on last edited by
    #1

    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?

    AnatolySA 1 Reply Last reply
    0
    • AnatolySA AnatolyS

      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?

      AnatolySA Offline
      AnatolySA Offline
      AnatolyS
      wrote on last edited by
      #2

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

      button.forceActiveFocus(Qt.TabFocus)
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved