Important: Please read the Qt Code of Conduct -

Keys.onReleased Premature trigger

  • I wanted to look into the QML key capturing mechanism, but immediately found a problem with it. If I keep either key pressed, it continues to register the event. Even if I just keep the right key pressed, and hence never released, it keeps triggering.

        Item {
            focus: true
            Keys.onPressed: {
                if (event.key == Qt.Key_Left) {
                    console.log("press left");
                    event.accepted = true;
            Keys.onReleased: {
                if (event.key == Qt.Key_Right) {
                    console.log("release right");
                    event.accepted = true;
            Keys.onReturnPressed: console.log("Pressed return");

  • Lifetime Qt Champion

    Its the auto repeat feature.
    In c++ you check if QKeyEvent::isAutoRepeat()
    to filter out if unwanted.
    I have no idea with QML :)

Log in to reply