[PyQt] About keyPressEvent

"Gustavo A. Dí­az" gustavo.diaz at gmail.com
Thu Aug 23 14:01:03 BST 2007

Andreas Pakulat escribió:
> On 23.08.07 00:54:59, "Gustavo A. Dí­az" wrote:
>> I did this time:
>> def keyPressEvent(self, event):
>>              if event.key() == QtCore.Qt.Key_Escape:
>>                  self.hide()
>>         if event.key() == QtCore.Qt.Key_Alt + QtCore.Qt.Key_Escape:
>>             self.hide()
>> Esc key only, hides the app.
>> Alt + Esc does not, it just close the app.
>> What is wrong?
> You didn't understand how a keypress translates into a key press event.
> A keypress (when you push down Alt) is directly creating a key press
> event, which is going to be delivered. On the next key press (the Esc
> key) you'll get another key press event. So the 2nd if is never true,
> also because event.key() always returns 1 keycode, not the sum of 2.
> What you probably want is
> if event.key() == QtCore.Qt.Key_Escape and (event.modifiers() &
> QtCore.Qt.AltModifier):
> ...
> Andreas
Yeah i missed that... sorry.. i am just still learning about PyQT and QT....

Anyway that do not work cause for sure, now that i am thinking, that key
combination to close an app is reserved by my window manager, which is
KDE... so maybe i will have to implement something related to kde (or PyKDE)

like Sundace make me remember:

 did you make sure that the Alt+Esc shortcut is not being 
preempted by something else, like your window manager for instance?

Don't know if is possible directly from QT.



/Gustavo A. Díaz/
*GDNet Projects*
www.gdnet.com.ar <http://www.gdnet.com.ar>
Gustavo A. Díaz
-------------- next part --------------
Skipped content of type multipart/related

More information about the PyQt mailing list