[Qt-interest] mousePressEvent() reports wrong coordinates
Nikos Chantziaras
realnc at arcor.de
Mon May 31 03:13:36 CEST 2010
I have a QWidget subclass in which I override mousePressEvent() and
mouseReleaseEvent(). The widget is viewable through a QScrollArea and
is set-up with QScrollArea::setWidget().
The problem is that when the QScrollArea scrolls the widget, and the
mouse is not moved, the mouse click handlers contain the wrong
coordinates (the ones prior to scrolling, from when the mouse was last
moved.) The only way to update the coordinates is to move the mouse.
This results in bugs like this:
The custom widget is displaying a document with hyperlinks in it. When
you click on a link, the document scrolls to a different position. Now,
if you don't move the mouse at all, and click again, mousePressEvent()
will report that the mouse is still over the hyperlink that was just
clicked, even though it scrolled up or down and the mouse is over a
different QWidget position. So even though the widget "moves away" from
the mouse, the coordinates are not updated since it's the widget that
moves relative to the mouse, not vice versa.
How can I solve this problem?
More information about the Qt-interest-old
mailing list