Results 1 to 5 of 5

Thread: Custom QApplication and keypress

  1. #1
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Custom QApplication and keypress

    Hi everyone,
    I want to detect key press and mouse event from any widget. So I inherit QApplication and re implement the notify function.
    I am able to detect mouse and key press event from any widget. But in some widget key press is not working fine. In lineEdit texts are not able to print escape key is not working in some widget.....

    But if i remove the implementation of notify the all things are fine.


    Qt Code:
    1. class MyApplication : public QApplication
    2. {
    3. Q_OBJECT
    4. public:
    5. MyApplication(int argc ,char** argv);
    6.  
    7. bool notify(QObject *obj, QEvent *e);
    8.  
    9.  
    10. };
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. bool MyApplication::notify(QObject *obj, QEvent *e)
    2. {
    3. return obj->event(e);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Can anybody please tell me what is the problem ?

    thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom QApplication and keypress

    You don't have to subclass for that.

    You can install an event filter on the QApplication instance.
    See QObject::eventFilter().

    Cheers,
    _

  3. #3
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Custom QApplication and keypress

    Thanks for reply.
    I have a doubt. I am using a stack widget. In which widget i will re implement the eventFilter ?

    I re implemented the eventFilter in a widget but nothing happened for key press and mouse click.

    Can you please tell me little bit more ?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom QApplication and keypress

    You don't have to implement the event filter in any widget, a normal QObject subclass will do.
    You then install an instance of that class on the QApplication instance as its event filter.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Custom QApplication and keypress

    Thanks.....

    It is working fine.

    QApplication::installEventFilter(QObject*) did the work for me.

Similar Threads

  1. Custom Qt "modules" from within a main QApplication
    By alitoh in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2012, 14:00
  2. QListWidget keypress capture ?
    By tonnot in forum Qt Programming
    Replies: 5
    Last Post: 29th September 2011, 20:07
  3. Replies: 2
    Last Post: 1st August 2011, 06:30
  4. fn+f1 keypress detect
    By oguzy in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 16:21
  5. keypress event
    By vishesh in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2007, 14:12

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.