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. Not receiving keyboard events in QML
Forum Updated to NodeBB v4.3 + New Features

Not receiving keyboard events in QML

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

    Hi All,
    I have written a small code for grabbing keyboard events in qml. Unfortunately I dont get any event in following code. Any suggestions please?
    (Also I dont get anything printed from onFocusChanged event)

    import QtQuick 2.7
    import QtQuick.Controls 2.1
    import QtQuick.Window 2.2

    Window {
    visible: true;
    width: Screen.width
    height: Screen.height

    Item  {
        id:keyLabelRect
        anchors.centerIn: parent
        height: 100
        width: 300
        focus: true
        Text {
            id:keyText
            anchors.centerIn: parent
            text:"Something"
            font.pointSize: 24; font.bold: true
        }
    
        onFocusChanged: {
            console.log("focus: ", focus)
        }
    
        Keys.enabled: true
        Keys.onPressed: {
            if(event.key === Qt.Key_F1) {
                keyText.text = "Key F1"
            }
            console.log(event.key)
        }
    }
    
    RoundButton {
        text: "X"
        height: 70
        width: 70
        onClicked: Qt.quit()
    }
    

    }

    1 Reply Last reply
    0
    • K Offline
      K Offline
      knishitosh
      wrote on last edited by
      #2

      solved .....

      import QtQuick 2.7
      import QtQuick.Controls 2.1
      import QtQuick.Window 2.2

      Window {
      id:keyWindow
      visible: true;
      width: Screen.width
      height: Screen.height
      Component.onCompleted: keyWindow.requestActivate()

      Item  {
          id:keyLabelRect
          anchors.centerIn: parent
          height: 100
          width: 300
          focus: true
          Text {
              id:keyText
              anchors.centerIn: parent
              text:"Something"
              font.pointSize: 24; font.bold: true
          }
      
          onFocusChanged: {
              console.log("focus: ", focus)
          }
      
          Keys.enabled: true
          Keys.onPressed: {
              if(event.key === Qt.Key_F1) {
                  keyText.text = "Key F1"
              }
              console.log(event.key)
          }
      }
      
      RoundButton {
          text: "X"
          height: 70
          width: 70
          onClicked: Qt.quit()
      }
      

      }

      1 Reply Last reply
      1

      • Login

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