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 keyboard keys unfunctionality
Forum Updated to NodeBB v4.3 + New Features

QML keyboard keys unfunctionality

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

    Hi,

    Why are the Plus and Minus keys caught and working as expected but other keys (the arrows) are not working nor do they cause no effect on the program, please?

    import QtQuick
    import QtQuick.Controls
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        
        Rectangle {
            id: square
            width: 100; height: 100
            anchors.centerIn: parent
            color: "green"
            focus: true
            
            Keys.onPressed:(event)=>{
                               switch(event.key) {
                                   case Qt.Key_Plus:
                                   square.scale += 0.2
                                   break;
                                   
                                   case Qt.Key_Minus:
                                   square.scale -= 0.2
                                   break;
                                   
                                   case Qt.Key_Up:
                                   square.y -= 8
                                   break;
                                   
                                   case Qt.Key_Down:
                                   square.y += 8
                                   break;
                                   
                                   case Qt.Key_Right:
                                   square.x += 8
                                   break;
                                   
                                   case Qt.Key_Left:
                                   square.x -= 8
                                   break;
                               }
                           }
        }
    }
    
    1 Reply Last reply
    0
    • ndiasN Offline
      ndiasN Offline
      ndias
      wrote on last edited by
      #2

      Hi @qcoderpro,

      You need to remove anchors.centerIn: parent.

      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