KeyPress events within a Label



  • Hello, I'm working on a QML application, and I have a ToolBar along the bottom of the ApplicationWindow, very similar to the example code. Within that ToolBar are several Labels, and I'd like the text in one of these labels to update when I press the P key. Right now I'm using the following code, lifted from this documentation page

    The code is:

                Label {
                    id: LockLabel
                    focus: true
                    Keys.enabled: true
                    Keys.onPressed:{
                        console.log("keypress")
                        if(event.key == Qt.Key_P){
                             pitchLockLabel.text = " Lock"
                            console.log("lock")
                            event.accepted = true
                        }
                    }
    

    My code does not appear to even register the "keypress" console output when P is pressed. My belief is that this is due to how I've got the Keys type set up, but I'm really quite new to QML and I'd like some insight into that. Any help would be appreciated!

    twall.



  • @twall said in KeyPress events within a Label:

    Within that ToolBar are several Labels

    Hi, make sure your 'LockLabel' is the first Label with focus: true
    LA



  • Currently it's the only Label with a 'focus: true'



  • Solved this by noticing a focus issue. Whoopsie!


Log in to reply
 

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