Results 1 to 3 of 3

Thread: C++/Qt5 - Install event filter on UI QPushButton

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default C++/Qt5 - Install event filter on UI QPushButton

    Qt Creator 3.5.1 (opensource)
    Based on Qt 5.5.1 (MSVC 2013, 32 bit)
    Windows 7

    Hello,

    This is the first time I've used the form designer in QtCreator.
    So far, so good. I have form that displays what I want.
    The problem comes when I try and install an event filter on a QPushButton (bRefresh).
    The button does not display, If I place the cursor where the pushbutton should be the eventFilter works.
    If I do not install the event filter the button shows, but of course the eventFilter does'nt get called.
    What am I doing wrong?

    Regards
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    2. {
    3. setupUi(this);
    4. ...
    5. ...
    6. bRefresh->installEventFilter(this); //is a QPushButton
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "ui_mainwindow.h"
    2.  
    3. class MainWindow : public QMainWindow, public Ui::MainWindow
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. MainWindow(QWidget *parent=0);
    9. ~MainWindow();
    10. bool eventFilter(QObject *obj, QEvent *event);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (obj == (QObject*)bRefresh)
    4. {
    5. if (event->type() == QEvent::Enter)
    6. {
    7. QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
    8. qDebug() << "enter";
    9. } else {
    10. if (event->type() == QEvent::Leave)
    11. {
    12. QApplication::restoreOverrideCursor();
    13. qDebug() << "leave";
    14. }
    15. }
    16. return true;
    17. } else {
    18. return QWidget::eventFilter(obj, event);
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

  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: C++/Qt5 - Install event filter on UI QPushButton

    Your event filter is filtering out all events for the button (returning true).
    So it will not get the show event or paint events, etc.

    Cheers,
    _

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

    jimbo (22nd December 2015)

  4. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++/Qt5 - Install event filter on UI QPushButton

    Hello anda_skoa,

    Many thanks.
    I must spend more time RTFM, than RTFInternet.

    Regards

  5. The following user says thank you to jimbo for this useful post:

    d_stranz (23rd December 2015)

Similar Threads

  1. Event Filter doesnt work on Drop Event
    By DNW in forum Qt Programming
    Replies: 3
    Last Post: 25th October 2015, 06:55
  2. Qt event filter hides the widget
    By Cupidvogel in forum Newbie
    Replies: 3
    Last Post: 8th April 2015, 11:30
  3. filter mouse event
    By sajis997 in forum Qt Quick
    Replies: 10
    Last Post: 16th February 2015, 07:26
  4. Replies: 2
    Last Post: 12th May 2012, 11:30
  5. Event filter question
    By d_stranz in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2011, 23:08

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.