Home > Enterprise >  qml does not accept keyboard event until i switch windows
qml does not accept keyboard event until i switch windows

Time:04-26

I am developing some kind of a video player in QML. I want to control it by Keyboard events but the problem is that the qml doesn't seem to accept any keyboard event until I switch the window and comeback to the app window. I tried with "focus: true" "enabled : true"

and "FocusScope: Item"

but nothing worked for me

CodePudding user response:

If you use Shortcut you should disable the shortcuts in your parent pages.

main.qml

ApplicationWindow 
{
    id:mainWindow

    Shortcut {
        id:backShortcut
        sequences: ["Esc", "Back"]

        onActivated: {
            console.log("Back Shortcut In main Page")
        }
    }
}

CustomPage.qml

Page{

    Component.onCompleted: {
        backShortcut.enabled=false
    }
    Component.onDestruction: {
        backShortcut.enabled=true
    }
    Shortcut {
        id:backShortcutCustomPage
        sequences: ["Esc", "Back"]
        onActivated: {
            console.log("Back Shortcut In Custom Page")
        }
    }
}
```

CodePudding user response:

I solved this problem by tracing the focus. The problem was during the frame/page switches I lost the focus. Hence I enabled it on each frame by forceActiveFocus.

  • Related