[Qt-interest] QDialog shown from a QGraphicsItem's mouseReleaseEvent

benswerts at telenet.be benswerts at telenet.be
Tue Feb 16 14:27:21 CET 2010


Hello all,

My problem in a nutshell: showing a QDialog in the mouseReleaseEvent of a QGraphicsItem will trigger a hoverEnterEvent and a hoverMoveEvent with wrong positions.

I would like to show a modal QDialog when a QGraphicsItem is clicked. So I construct and show the dialog in the mouseReleaseEvent of the item. At the start of this function the 'event->pos()' will be a position within the item's bounding box. When the dialog is visible (exec'ed), the mouse can be moved without the item/scene/view knowing. When the dialog is closed, the mouse is normally not in the QGraphicsItem anymore. 

When leaving the mouseReleaseEvent function, I get 2 events for the QGraphicsItem: a hoverEnterEvent and a hoverMoveEvent. Inspecting the events themselves shows that they have a position (event->pos() and event->lastPos()) that is the same as the one at the start of mouseReleaseEvent. Obviously those positions do not correspond anymore with the current mouse position. It is the QGraphicsScenePrivate's dispatchHoverEvent function which is called from QGraphicsScene's mouseReleaseEvent that triggers these events. Because I implemented hoverEnterEvent and hoverMoveEvent I noticed unexpected behaviour.

Now I'm not sure whether this is in fact a bug or not. I tried a number of things to solve the problem, but the only working solution I found involved showing the dialog after I let the event loop spin (QTimer::singleShot).
Am I missing a better way?

Thanks in advance for any insights.
Greets,


  Ben






More information about the Qt-interest-old mailing list