[Solved] eventFilter appears to be not working pressing mouse button over a Qt button widget...
-
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
-
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);
}@ -
Hi,
I am trying same program but i am not getting windowI am get like "The program has unexpectedly finish"
window.exe exited with code -1073741819plz help me.