PDA

View Full Version : Find what event is triggered on an action



TEAmerc
30th September 2015, 18:52
I've made a class (inherited QMainWindow - I'll call it MyMainWindow here) where I've reimplemented the dropEvent and the mousePressEvents in order to let me re-parent QDockWidgets by dragging and dropping them between different instances of MyMainWindow. It currently re-parents them fine, except after re-parenting them it doesn't go straight to letting the user choose where to dock the re-parented QDockWidget on the MyMainWindow like I was hoping it would.

I found however that it will do this after I move my mouse over the top left corner of the MyMainWindow object's dock. I wanted to know if there was a way that I could capture what events are occurring so when I mouseover the top left of the widget I could find what signal it was and manually trigger it at the end of my dropEvent.

Alternatively if there was a way to manually call the function that lets a user move where a QDockWidget is docked that would also work.

Thanks

anda_skoa
1st October 2015, 08:32
You can see all events going to an object by installing an event filter on that opject.
You can see all events by installing an event filter on the application object.

It might also be useful, maybe even more than tracking events, to look at the code of QMainWindow.

Cheers,
_

TEAmerc
1st October 2015, 19:14
Thanks for the response! Also if I want to trigger an event would all I have to do be something like this:



QEvent reParentEvent(QEvent::LayoutRequest); // Widget layout needs to be redone - Type 76
QApplication::sendEvent(this, &reParentEvent);


Or is there something more to send because so far I haven't been able to make the fix and I'm not sure if I haven't gotten the correct event (there's 3 likely ones, but I may be wrong as there's a lot of events being passed) or if I'm not triggering the event properly.

Added after 39 minutes:

Nevermind, I was triggering it right. It turns out it was a QDockWidget event and not a QMainWindow event that I needed to trigger though. For anyone who comes up with a similar problem in the future I solved it by putting this in my reimplemented dropEvent function after I reparented the QDockWidget:



QEvent reParentEvent1(QEvent::MouseMove); // Mouse move (QMouseEvent) - 5
QApplication::sendEvent(child, &reParentEvent1);


That allowed the dock widget to immediately go to letting the user place its new child widget in the dock.

Thanks for the help!