PDA

View Full Version : keypressevent with pyqt4



coldlin
2nd October 2007, 19:56
Hi to all!!
I'm new with python and qt, and i'm trying to make my program,written with pyqt4 in linux, execute some code when I press a keyboard button. I can't understand how to implement the keyPressEvent in my program :(
Searching with google i found this:



class Test(QtGui.QTextEdit):
def keyPressEvent(self, e):
print e.key()
e.ignore()


but this won't work to me, 'cause it declares a QTextEdit class, but i use a QWidget, so the .key() doesn't work :(
How can I do?? Thaks to all!!!

P.S. Sorry for the ignorance and the english.

jpn
3rd October 2007, 10:20
'cause it declares a QTextEdit class, but i use a QWidget, so the .key() doesn't work :(
But key() is a method of QtGui.QKeyEvent, not QTextEdit nor QWidget..

coldlin
3rd October 2007, 15:18
but if i use the key() with qwidget it doesn't work. I can't post the error now, i'll post it later if it could help.

coldlin
3rd October 2007, 17:52
I tried to change the test's class from QTextEdit and QWidget and it actually works!
But... I think I have some focus problem, 'cause in my main class it doesn't work.

I tried to set focuspolicy to tabfocus, focus to tabfocusreason, with no advantage.
I tried grabkeyboard() but it says


X Error: BadWindow (invalid Window parameter) 3
Major opcode: 31 (X_GrabKeyboard)
Resource id: 0x0


what could I do?