PDA

View Full Version : Making QMouseEvent only triggered by MousePress and ignore move and release



mohatem
18th September 2017, 17:46
I am using a function called InstallEventHandler which takes the name of the event and install handler to it

installEventHandler("QWidget", "QMouseEvent","mouse_event")

in which the QWidget is the type the the event handler is installed to, the QMouseEvent is the event that causes the handler to be called, and the mouse_event is the handler.

I want the function to be triggered when mouse is pressed only but I am encountered with a problem that the QMouseEvent is generated with mouse moves and releases too not only QMousePressEvent. Which make the fuction gets called thousands of times and misses my code.

I am trying since days to find a way and searching all the available methods but non is working.

d_stranz
19th September 2017, 02:44
Modify your method so it takes a 4th argument of QEvent::Type. For the case you describe above, that would be QEvent::MouseButtonPress. Inside your method, you check to see that pEvent->type() == QEvent::MouseButtonPress, and if it is, you call the event handler.



installEventHandler( "QWidget", "QMouseEvent", QEvent::Type eventType, "mouse_event" );


Alternatively, modify your event handler so it takes the QEvent pointer:



void eventHandler( QWidget * sender, QEvent * pEvent );


and inside your event handler you can choose to act only if the event type is MouseButtonPress.

I am not really sure why you are trying to reinvent this wheel. Qt already has the capability to install an event handler on any QObject. See QObject::installEventFilter().

mohatem
19th September 2017, 13:39
The problem is that I don't have access to the function, it's created by "squish" and I am only using it.
I tried to use qt QObject::installEventFilter, but I am encountered with the problem that install event filter must take the object I want to Install the filter to.

While here it takes the type "QWidget" which is everything and install the filter to them even the dynamically created widgets during runtime.

d_stranz
19th September 2017, 17:26
I see. Is there a "squish" users forum? You might get more help there by people familiar with it.

What gets sent to your "mouse_event" callback function? If there is a pointer to the event itself, you can still use the event type to select out the ones you want.


Which make the function gets called thousands of times and misses my code.

I do not know what you mean by "misses my code". The "mouse_event" function is something you have written, right?