QML在我切换Windows之前不接受键盘事件

发布于 2025-01-23 21:24:55 字数 130 浏览 2 评论 0原文

我正在QML开发某种视频播放器。我想通过键盘事件控制它,但问题是QML似乎不接受任何键盘事件,直到我切换窗口并卷土回到应用程序窗口。我尝试了 “焦点:真” “启用:true”

和 “焦点:项目”

,但对我没有任何帮助

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

━╋う一瞬間旳綻放 2025-01-30 21:24:55

如果您使用快捷方式,则应禁用父页面中的快捷方式。

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")
        }
    }
}
```

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")
        }
    }
}
```
謸气贵蔟 2025-01-30 21:24:55

我通过追踪重点解决了这个问题。问题是在帧/页面开关期间,我失去了焦点。因此,我在每个帧上启用了 /a>。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文