QML keyboard keys unfunctionality
-
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; } } } }
-
Hi @qcoderpro,
You need to remove anchors.centerIn: parent.