PyQt trigger a button with ctrl+Enter

8.6k views Asked by At

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

1

There are 1 answers

1
eyllanesc On BEST ANSWER

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)