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. KeyPress events within a Label

KeyPress events within a Label

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.3k 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.
  • T Offline
    T Offline
    twall
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      twall
      wrote on last edited by
      #4

      Solved this by noticing a focus issue. Whoopsie!

      1 Reply Last reply
      0
      • ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #2

        @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

        1 Reply Last reply
        0
        • T Offline
          T Offline
          twall
          wrote on last edited by
          #3

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            twall
            wrote on last edited by
            #4

            Solved this by noticing a focus issue. Whoopsie!

            1 Reply Last reply
            0

            • Login

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