Moayyad Yaghi
Moayyad Yaghi

Reputation: 3722

getting keyboard events with pyqt

i converted recently from wxpython to pyqt and im still facing alot of problems since im still noob in pyqt

so is it possible to detected if user pressed (CTRL+key ) in pyqt ? and how ?



i've been trying to find an answer for this for 3 days . if you know website or a good place to learn pyqt, it will be highly appreciated

thanx in advance

Upvotes: 3

Views: 5870

Answers (2)

szupie
szupie

Reputation: 856

Add a QShortcut and listen to its activated() signal, then perform the action in the slot.

Or you could reimplement QWidget and define keyPressEvent to what you like. Check for the event parameter's modifiers() and key() to see if they match with what you want. This listens for shortcut keys when the QWidget has focus.

Upvotes: 8

Rini
Rini

Reputation: 254

As for websites to learn, this is the official documentation - it takes some getting used to, but is quite helpful once you get the lay of the land (so to speak). This tutorial is what I walked through to get the initial idea, before discovering the documentation.

Good luck!

P.S. You might also look at QAction, if you are trying to map your Ctrl+X to an action that may also be performed by a menu or toolbar button... It incorporates a shortcut along with icons and/or text in a very convenient package. Just FYI.

Upvotes: 2

Related Questions