Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-19333

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.

    XMLWordPrintable

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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              earthdomain Earth Domain (Inactive)
              miseppan1 Mikko Seppänen (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes