Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] eventFilter appears to be not working pressing mouse button over a Qt button widget...
Forum Updated to NodeBB v4.3 + New Features

[Solved] eventFilter appears to be not working pressing mouse button over a Qt button widget...

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 17.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    st2000
    wrote on last edited by
    #1

    Hi...

    We have been investing time into eventFilter trying to capture every mouse action in order to control a watch dog timer. The problem is that no matter how the eventFilter is inserted, and no matter how many places we insert it, we only see a QEvent::MouseButtonPress event when the mouse button is presses over the Qt window where there is no Qt button widget defined.

    I had thought the eventFilter would pick up every mouse button press. I thought I would simply kick the watch dog and return false so that Qt and our code would process the button press as originally intended.

    But no matter what we have tried, we only see mouse button presses where there are no buttons to press. Almost exactly what we did not want (certainly not what we need).

    Does anyone have ideas as to why the eventFilter is not receiving the mouse events first? Really, what is the point of filter events if you can not stop something before Qt processes it?

    -thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Cayan
      wrote on last edited by
      #2

      You can stop a mouse button press on its clicked/pressed/released signal, just add an if and returns...
      I'm having some trouble with the eventFilter aswel, sometimes it does not work as expected :S

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Richard Neal
        wrote on last edited by
        #3

        To get all of the applications mouse events you would need to install the event filter on the application object.

        (e.g.)
        mainwindow.h
        @class MainWindow : public QMainWindow, private Ui_MainWindow
        {
        Q_OBJECT
        public:
        MainWindow( QWidget *parent = 0, Qt::WindowFlags f = 0 );
        ~MainWindow();

        protected:
             bool eventFilter(QObject *obj, QEvent *event);
        

        };@

        mainwindow.cpp
        @MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags f ) :
        QMainWindow( parent, f )
        {
        setupUi( this );
        qApp->installEventFilter( this );
        }

        MainWindow::~MainWindow()
        {
        }

        bool MainWindow::eventFilter(QObject *obj, QEvent *event)
        {
        switch( event->type() ){
        case QEvent::MouseButtonDblClick:
        qDebug() << "Mouse Button Double Clicked";
        break;
        case QEvent::MouseButtonPress:
        qDebug() << "Mouse Button Pressed";
        break;
        case QEvent::MouseButtonRelease:
        qDebug() << "Mouse Button Released";
        break;
        default:
        break;
        }
        // pass the event on to the parent class
        return QMainWindow::eventFilter(obj, event);
        }@

        For every positive is a negative and every negative is a positive.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          st2000
          wrote on last edited by
          #4

          @Richard Neal
          Ah! I did not realize "qApp" existed let alone could be used here. That's what was missing! Simple now. Impossible yesterday!

          -thanks

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mvenkat061
            wrote on last edited by
            #5

            Hi,
            I am trying same program but i am not getting window

            I am get like "The program has unexpectedly finish"
            window.exe exited with code -1073741819

            plz help me.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved