PDA

View Full Version : How to prevent "What's this?" on right click



d_stranz
25th November 2013, 22:04
I have implemented a custom state machine for handling mouse and keyboard interactions with a graphical plot. The state machine is attached to a QGraphicsView and installs an event filter on the view to intercept mouse, keyboard, and wheel events. I recently ported this to Qt 5, and now I am observing different behavior during right mouse clicks.

In Qt 4.8, I could turn off context menus when I wanted to turn on right mouse click handling in my state machine, and this prevented both the context menus and the "What's this?" box from appearing. In Qt 5, the "What's this?" box appears all the time. It also seems to interfere with the event filter in the state machine, but this is very hard to debug because, of course, if a breakpoint is set, clicking the mouse immediately transfers to the debugger and messes things up in the state machine.

I added a case to handle QEvent::WhatsThis event types in my event filter, but this condition is never hit, so apparently the event never makes it that far. If I return "true" from the event filter for the mouse button press event, call accept(), or call ignore() on the mouse event, the "what's this?" box still appears.

The graphics view widget is embedded as a child widget in a popup dialog. This dialog does have a "What's this" string defined, and it is this text that is displayed when I double-click the "What's this?" box. So the event seems to be triggered somewhere way up the chain of command, not at the level of my graphics view widget.

Given that my graphics view widget is a reusable component that has no idea about where it is being used, and that the popup dialog doesn't have any idea about the workings of the graphics view widget, how can I disable the "What's this?" behavior of the popup dialog from inside my state machine? I still want it to work when the mouse is outside my widget, so turning it off in the dialog itself is not an option.

Any ideas?

-------
Later: After a bit more research, I have found that if I set the widget attribute Qt::WA_CustomWhatsThis on the widget that uses the state machine, the QEvent::WhatsThis now gets passed to the event filter in the state machine. Unfortunately, it hits after the "What's this?" box is displayed in the graphics view, so I cam still no closer to a solution. I also added a case for QEvent::QueryWhatsThis, but that isn't passed in even with the custom whats this flag set.

So, still looking for ideas.

-------
Still later: OK, if I call setContextMenuPolicy( Qt:: PreventContextMenu ) or setWhatsThis( "" ) in the popup dialog constructor then the right mouse press works as desired. But then I have no "What's this" help on the popup dialog. So it doesn't seem as though there is a way to implement "What's this" behavior for a parent widget while disabling it for a child contained within that parent.

And I'm still looking for ideas...