Results 1 to 3 of 3

Thread: keyPressEvent not being caught

  1. #1
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default keyPressEvent not being caught

    I've promoted a comboBox part and then in the source file I put the following code:
    Qt Code:
    1. void promotedPart::keyPressEvent(QKeyEvent* e)
    2. {
    3. QComboBox::keyPressEvent(e);
    4. if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
    5. {
    6. handleReturnPressed();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Nothing happens.

    BTW: Dunno how to Thank you all so much for the better-than-excellent support I've received from you guys in past posts, Linux and Qt is bloody fantastic !! You guys make it so. Without you guys, It would just be another os and development environment.
    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: keyPressEvent not being caught

    Quote Originally Posted by vieraci View Post
    Nothing happens.
    Could you verify that the method actually gets called? You can do that by putting a qDebug() statement there. I suspect that Return/Enter might be handled on a different level - even in an event filter of the combobox. If you verify that the method is not called, try reimplementing event() instead or apply an event filter on your combobox subclass and handle it there. At least the last solution has to work (and you can do that even without subclassing).

    BTW: Dunno how to Thank you all so much for the better-than-excellent support I've received from you guys in past posts, Linux and Qt is bloody fantastic !! You guys make it so. Without you guys, It would just be another os and development environment.
    Thanks!
    Thx.

  3. The following user says thank you to wysota for this useful post:

    vieraci (30th October 2007)

  4. #3
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keyPressEvent not being caught

    Strange thing:
    Not sure what I did now.
    I inserted some qDebug lines and found keyPressEvent() was now being called, and also promotedPart::returnPressed() began to function too !!
    But when I dropped keyPressEvent(), promotedPart::returnPressed() stopped working

Similar Threads

  1. keypressevent with pyqt4
    By coldlin in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2007, 16:52
  2. QTreeWidget keyPressEvent
    By hgedek in forum Qt Programming
    Replies: 3
    Last Post: 18th August 2007, 16: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.