QML Key event Qt.key_Minus can't used
-
wrote on 29 Apr 2016, 02:43 last edited by p3c0
I run some .qml file with qmlscene, but key event Qt.key_Plus has no effect, and when I pressed Qt.key_Minus several times, the GreenSquare became larger, Qt version: 5.6.0, OS: redhat 6/ubuntu.
Codes:
keys.qml:import QtQuick 2.0 DarkSquare { width: 400; height: 200 GreenSquare { id: square x: 8; y: 8 } focus: true Keys.onLeftPressed: square.x -= 8 Keys.onRightPressed: square.x += 8 Keys.onUpPressed: square.y -= 8 Keys.onDownPressed: square.y += 8 Keys.onPressed: { switch (event.key) { case Qt.Key_Plus: square.scale += 0.2 break; case Qt.Key_Minus: square.scale -= 0.2 break; } } }
DarkSquare.qml:
import QtQuick 2.0 Rectangle { width: 48 height: 48 color: "black" border.color: Qt.darker(color) }
GreenSquare.qml:
import QtQuick 2.0 DarkSquare { width: 48 height: 48 color: "green" border.color: Qt.lighter(color) }
What can I do to avoid this bug, or fix this bug?
-
I run some .qml file with qmlscene, but key event Qt.key_Plus has no effect, and when I pressed Qt.key_Minus several times, the GreenSquare became larger, Qt version: 5.6.0, OS: redhat 6/ubuntu.
Codes:
keys.qml:import QtQuick 2.0 DarkSquare { width: 400; height: 200 GreenSquare { id: square x: 8; y: 8 } focus: true Keys.onLeftPressed: square.x -= 8 Keys.onRightPressed: square.x += 8 Keys.onUpPressed: square.y -= 8 Keys.onDownPressed: square.y += 8 Keys.onPressed: { switch (event.key) { case Qt.Key_Plus: square.scale += 0.2 break; case Qt.Key_Minus: square.scale -= 0.2 break; } } }
DarkSquare.qml:
import QtQuick 2.0 Rectangle { width: 48 height: 48 color: "black" border.color: Qt.darker(color) }
GreenSquare.qml:
import QtQuick 2.0 DarkSquare { width: 48 height: 48 color: "green" border.color: Qt.lighter(color) }
What can I do to avoid this bug, or fix this bug?
wrote on 29 Apr 2016, 13:15 last edited by@neng
If you mean that size of rectangle increased after scale become < 0, then Item.scaleA scale of less than 1.0 causes the item to be rendered at a smaller size, and a scale greater than 1.0 renders the item at a larger size. A negative scale causes the item to be mirrored when rendered.
-
wrote on 3 May 2016, 08:02 last edited by
Thank you for the reply!
but key event Qt.key_Plus has no effect, mybe I need to change the key instead of Qt.key_plus to enlarge the target. -
wrote on 3 May 2016, 08:20 last edited by
I Use Qt.key_0 to enlarge the rectangle, the rectangle is enlarged successfully, I think it's qt quick's bug.
-
I Use Qt.key_0 to enlarge the rectangle, the rectangle is enlarged successfully, I think it's qt quick's bug.
wrote on 3 May 2016, 19:41 last edited by@neng said:
Is Keys.onPressed executed when you press "+"? And if yes, what the value of event.key?
-
wrote on 4 May 2016, 01:06 last edited by
Thanks, it's my problem.
If you need event Qt.key_plus, you must press Shift and =, else if you press =, the event is Qt::Key_Equal.
3/6