Results 1 to 2 of 2

Thread: EventFilter show events returned

  1. #1
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default EventFilter show events returned

    Hi i put the class eventfilter but how i can show in the main of my program the events of this filter. Class:
    Qt Code:
    1. class FiltroDeEventosPersonalizado
    2. : public QObject
    3. {
    4. Q_OBJECT
    5.  
    6. protected:
    7.  
    8. bool eventFilter(QObject *obj, QEvent *event) override;
    9. };
    To copy to clipboard, switch view to plain text mode 
    Method :
    Qt Code:
    1. bool
    2. FiltroDeEventosPersonalizado::eventFilter(
    3. QObject obj,
    4. QEvent event)
    5. {
    6. if (event->type() == QEvent::KeyPress) {
    7. QKeyEvent keyEvent = static_cast<QKeyEvent>(event);
    8. if( keyEvent->key() == Qt::Key_A )
    9. qDebug() << "Tecla 'A' presionada";
    10. return true;
    11. }
    12.  
    13. return QObject::eventFilter(obj, event);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Main of my program:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <filtrodeeventospersonalizado.h>
    3. #include <QDebug>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9. //i want show the events with Qdebug
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 6th October 2016 at 15:56. Reason: changed [quote] to [code]

  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: EventFilter show events returned

    You need to install the event filter, e.g. on the application object.
    See QObject::installEventFilter().

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 10th September 2013, 12:15
  2. Replies: 1
    Last Post: 28th July 2011, 17:32
  3. Replies: 1
    Last Post: 6th May 2011, 09:25
  4. Replies: 6
    Last Post: 14th October 2010, 06:58
  5. MAC: Getting Dock widget show/hide events
    By jay in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2010, 08: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.