Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
4.7.1, 4.7.2, 4.7.3
-
None
-
Windows XP, Windows7
Description
In a QGraphicsView hoverLeaveEvent and hoverEnterEvent are called outside an item (QGraphicsRectItem). The hover events get generated at points to the left or above the item. Also, note that the event's pos() printed out in the hover functions (example below) show that x or y values of one less than the rect's position. (In the example, the rectangle is positioned at 5,5, but the hover event can be generated at 4.x,4.x. Note that the hover events work as expected to the right or below the box.
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsSceneHoverEvent>
#include <QGraphicsRectItem>
#include <QDebug>
class HoveringRectItem : public QGraphicsRectItem
{ public: HoveringRectItem(int x, int y, int w, int h) : QGraphicsRectItem(x, y, w, h) { setAcceptsHoverEvents(true); }virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent *event )
{ qDebug() << __FUNCTION__ << event->pos(); setPen(QPen(Qt::red)); }virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent *event )
{ qDebug() << __FUNCTION__ << event->pos(); setPen(QPen(Qt::black)); }};
int main(int argc, char** argv)
{
QApplication *app = new QApplication(argc, argv);
QGraphicsView view;
view.scale(10, 10);
QGraphicsScene scene;
view.setScene(&scene);
scene.addItem(new HoveringRectItem(5, 5, 5, 5));
view.show();
app->exec();
}
Attachments
Issue Links
- relates to
-
QTBUG-17985 QGraphicsScenePrivate::itemsAtPosition creates 1x1 selection rectangle in scene coord instead of screen coord
- Closed