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



  • 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?



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

    button.forceActiveFocus(Qt.TabFocus)

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.