QML Key event Qt.key_Minus can't used



  • 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?



  • @neng
    If you mean that size of rectangle increased after scale become < 0, then Item.scale

    A 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.
    


  • 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.



  • I Use Qt.key_0 to enlarge the rectangle, the rectangle is enlarged successfully, I think it's qt quick's bug.



  • @neng said:

    Is Keys.onPressed executed when you press "+"? And if yes, what the value of event.key?



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.