Home > Blockchain >  QML Button assign arrow shortcut
QML Button assign arrow shortcut

Time:07-18

Is it possible to assign an arrow shortcut to a QML Button? With the Action item I can assign a shortcut by string or by KeySequence (https://doc.qt.io/qt-6/qml-qtquick-controls2-action.html#shortcut-prop), but how can I assign a shortcut of an arrow?

CodePudding user response:

you can use Shortcut ,like this :

import QtQuick
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Shortcut")

    Button {
        id: button
        x: 199
        y: 144
        width: 190
        height: 105
        text: qsTr("Button")
        Shortcut
        {
            sequence:"Up" // "Down" , "Right" ,"Left"
            onActivated:button.clicked()
        }

        onClicked:
        {
            console.log("Up Arrow")
        }
    }


}

"Up" , "Down" , "Right" ,"Left" used for Arrows in keyboard.

  • Related