Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt trigger a button with ctrl+Enter

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

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.

How can I trigger the OkButton with ctrl+Enter

like image 595
tisaconundrum Avatar asked Sep 05 '17 12:09

tisaconundrum


1 Answers

According to the docs:

Qt.Key_Enter 0x01000005 Typically located on the keypad.

That is to say when you set Enter we refer to the key that is on the numeric keypad.

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)
like image 185
eyllanesc Avatar answered Sep 28 '22 08:09

eyllanesc