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. qml : Keys.onPressed does not work but Keys.onReleased works fine inside FocusScope.Please help me in fixing the issue.

qml : Keys.onPressed does not work but Keys.onReleased works fine inside FocusScope.Please help me in fixing the issue.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • Sudo007S Offline
    Sudo007S Offline
    Sudo007
    wrote on last edited by Sudo007
    #1

    Hey everyone, I'm having an issue with keyPress events in lListView written inside FocusScope
    Keys.onReleased works but Keys.onPressed does not work.
    In fact, not even Keys.onUpPressed is not working. Please help me in fixing this.

    Thanks in advance.

    raven-worxR 1 Reply Last reply
    0
    • Sudo007S Sudo007

      Hey everyone, I'm having an issue with keyPress events in lListView written inside FocusScope
      Keys.onReleased works but Keys.onPressed does not work.
      In fact, not even Keys.onUpPressed is not working. Please help me in fixing this.

      Thanks in advance.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Sudo007
      show some code pls

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Sudo007S Offline
        Sudo007S Offline
        Sudo007
        wrote on last edited by raven-worx
        #3
        import QtQuick 2.2
        
        FocusScope {
            id:mainPage
            
            signal somethingWasClicked(var sender, var arguments)
        
            function createSpyFunction(object) {
                return function() { somethingWasClicked(object, arguments) }
            }
        
            function crawlChildren(obj) {
                if (obj.Keys.onPressed) {
                    Object.defineProperty(obj, '__clickedFunction', { value: createSpyFunction(obj) })
                    obj.Keys.onPressed.connect(obj.__clickedFunction)
                }
        
                if (obj.children) {
                    for (var i = 0; i < obj.children.length; i++) {
                        crawlChildren(obj.children[i])
                    }
                }
            }
        	
            Component.onCompleted: {
                mainPage.crawlChildren(screenBG)
            }
        
            Rectangle{
                id: screenBG
                anchors.fill: parent
        
             
          Keys.onPressed: {
        
                console.log("#onPressed#")
        
                switch(event.key)
                {
                    case Qt.Key_Up:// not working
                        console.log('onPressed##Key_Up was pressed')
                        break
                    case Qt.Key_Down: // only down key event is triggred 
                         console.log('onPressed##Key_Down was pressed')
                         break
                }
             }
            }  
            Rectangle {
                z: 99999
                anchors.fill: parent
                color: "black"
            }
        }
        
        
        // There is child screen ( qml page having List View ). for which down key event works but not up key
        
        //
            // Display the configured users as a vertical list of 'menubutton' items, one per user.
            // /// usr.qml
            ListView{
                id: userList
                width: parent.width
                anchors.top: usersCountBar.bottom
                anchors.bottom: parent.bottom
        
                focus: true
                clip: true
            // ..
            }
        
        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