Receive key strokes inside QtQuick.Dialogs 1.2? (How to deal with the focus)



  • Button {
           onPressed: {
               dialog.open()
               f.focus = true
           }
    
           text: "Record key"
       }
    
    Dialog {
           id: dialog
    
           contentItem: Rectangle {
               color: f.activeFocus ? "red" : "yellow"
               focus: true
               implicitHeight:  200
               implicitWidth:   300
                   Text {
                       id: f
                       anchors.fill: parent
                       focus: true
                       anchors.centerIn: parent
                       text: "Press key"
    
                       Keys.onPressed: {
                           focus: true
                           console.log( "Key: " + event.key )
                      }
                }
           }
    }
    

    Is there a better way to make a Dialog listening to a single key stroke? I fiddled around with FocusScope but I could not get anything working, except the version where the focus is set manually outside the dialog.


Log in to reply
 

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