PyQt 用 ctrl+Enter 触发一个按钮 [英] PyQt trigger a button with ctrl+Enter
本文介绍了PyQt 用 ctrl+Enter 触发一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为我的应用程序中的 Ok 按钮触发我尝试的当前代码是这样的:
I'm trying to make a trigger for the Ok button in my application The current code I tried was this:
self.okPushButton.setShortcut("ctrl+Enter")
然而,它不起作用,这是有道理的.我尝试查找一些关键序列 here,但是,如果我尝试使用 shift
或 alt
键,同样会出现类似的问题.
However, it doesn't work, which kind of makes sense. I tried looking up some key sequences here, but, again, a similar issue if I try with the shift
or alt
keys.
如何使用 ctrl+Enter
推荐答案
根据 文档:
Qt.Key_Enter 0x01000005 通常位于键盘上.
Qt.Key_Enter 0x01000005 Typically located on the keypad.
也就是说当你设置Enter
时,我们指的是数字键盘上的那个键.
That is to say when you set Enter
we refer to the key that is on the numeric keypad.
但是如果你想使用默认的输入,你必须使用Return
.
But if you want to use the default enter you must use Return
.
self.okPushButton.setShortcut("Ctrl+Return")
# seq = QKeySequence(Qt.CTRL+Qt.Key_Return)
# self.okPushButton.setShortcut(seq)
这篇关于PyQt 用 ctrl+Enter 触发一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文