Results 1 to 4 of 4

Thread: keypressevent with pyqt4

  1. #1
    Join Date
    Oct 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default keypressevent with pyqt4

    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:

    Qt Code:
    1. class Test(QtGui.QTextEdit):
    2. def keyPressEvent(self, e):
    3. print e.key()
    4. e.ignore()
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: keypressevent with pyqt4

    Quote Originally Posted by coldlin View Post
    '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..
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keypressevent with pyqt4

    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.

  4. #4
    Join Date
    Oct 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keypressevent with pyqt4

    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
    Qt Code:
    1. X Error: BadWindow (invalid Window parameter) 3
    2. Major opcode: 31 (X_GrabKeyboard)
    3. Resource id: 0x0
    To copy to clipboard, switch view to plain text mode 

    what could I do?

Similar Threads

  1. QTreeWidget keyPressEvent
    By hgedek in forum Qt Programming
    Replies: 3
    Last Post: 18th August 2007, 16:33
  2. PyQt4 to Py3exe problem
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 9th August 2007, 19:33
  3. F2 keyPressEvent Not Capturing
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2007, 20:41
  4. Handling of dead keys in keyPressEvent()
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2006, 12:26
  5. KeyPressEvent behaves strange, skips the F key.
    By pir in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2006, 17:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.