Results 1 to 4 of 4

Thread: Overwrite QKeyEvent

  1. #1
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Overwrite QKeyEvent

    Hello everibody

    I need get how to overwrite the QKeyEvent, to get the tab behaviour with the enter-return key.

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Overwrite QKeyEvent

    You could more easily override a QWidget and reimplement its keyPressEvent() or keyReleaseEvent(), catch the Enter Key, then do whatever you want...

    Qt Code:
    1. #ifndef KEY_WIDGET_H
    2. #define KEY_WIDGET_H
    3.  
    4. #include <QWidget>
    5.  
    6. class KeyWidget : public QWidget
    7. {
    8. public:
    9. KeyWidget();
    10. virtual ~KeyWidget();
    11.  
    12. protected:
    13. void keyReleaseEvent(QKeyEvent * ke);
    14. }
    15.  
    16. #endif //KEY_WIDGET_H
    17.  
    18. #include "keywidget.h"
    19.  
    20. KeyWidget::KeyWidget() {}
    21. KeyWidget::~KeyWidget() {}
    22.  
    23. void keyReleaseEvent(QKeyEvent * ke)
    24. {
    25. if(ke->key() == Qt::Key_Return)
    26. {
    27. //do something...
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Overwrite QKeyEvent

    Ok, but how I can use this reimplemented QWidget's function on a desired widget?

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Overwrite QKeyEvent

    either
    * derive from the widget and override the method there
    * or install an event filter QObject::installEventFilter() (this is the way to go if you need to watch many widgets and esp. if you have to watch widgets that you did/can not implement yourself.

Similar Threads

  1. getSaveFileName overwrite check question
    By Lexrst in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 10:26
  2. QKeyEvent Gives Odd Response to SpaceBar
    By GTBuilder in forum Newbie
    Replies: 1
    Last Post: 2nd August 2008, 22:15
  3. QKeyEvent Problem
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2008, 00:36
  4. QKeyEvent
    By peace_comp in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2008, 14:13
  5. what's mean of the member of QKeyEvent
    By sunote in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2007, 22:25

Tags for this Thread

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.