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

Mouse hover events are (potentially) unnecessarily being sent to items

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.9.6, 5.12.3
    • None

    Description

      I have a FPS counter that is implemented by spinning a Rectangle:

      https://github.com/mitchcurtis/slate/blob/master/app/qml/ui/FpsCounter.qml#L35

      I recently noticed that if I leave my cursor still over the item that contains the FpsCounter (doesn't have to be over the counter, just anywhere in its parent item), that item will get sent hover events constantly.

      I'm not sure if it's a bug or not, but it seems unnecessary to send hover events to an item that uses them simply because a child item that doesn't use them is rotating.

      import QtQuick 2.0
      import QtQuick.Window 2.0
      
      import App 1.0
      
      Window {
          id: root
          width: 640
          height: 480
          visible: true
      
          property int fps
      
          PaintedItem {
              anchors.fill: parent
      
              Rectangle {
                  id: rotationItem
                  width: 100
                  height: 100
                  color: "salmon"
                  anchors.bottom: parent.bottom
      
                  property int timesUpdated: 0
      
                  NumberAnimation on rotation {
                      from: 0
                      to: 360
                      duration: 500
                      loops: Animation.Infinite
                  }
      
                  onRotationChanged: ++timesUpdated
              }
      
              Timer {
                  interval: 1000
                  repeat: true
                  running: true
                  onTriggered: {
                      root.fps = rotationItem.timesUpdated / (interval / 1000);
                      rotationItem.timesUpdated = 0;
                  }
              }
          }
      }
      
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QQuickItem>
      
      class CustomItem : public QQuickItem
      {
          Q_OBJECT
      
      public:
          CustomItem() {
              setAcceptedMouseButtons(Qt::AllButtons);
              setAcceptHoverEvents(true);
          }
      
          void hoverEnterEvent(QHoverEvent *event) override
          {
              qDebug() << "hoverEnterEvent:" << event;
              QQuickItem::hoverEnterEvent(event);
          }
      
          void hoverMoveEvent(QHoverEvent *event) override
          {
              qDebug() << "hoverMoveEvent:" << event->posF();
              QQuickItem::hoverMoveEvent(event);
          }
      
          void hoverLeaveEvent(QHoverEvent *event) override
          {
              qDebug() << "hoverLeaveEvent:" << event;
              QQuickItem::hoverLeaveEvent(event);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          qmlRegisterType<CustomItem>("App", 1, 0, "CustomItem");
      
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      
          return app.exec();
      }
      
      #include "main.moc"
      
      22:34:14: Starting /Users/mitch/dev/temp/quick-qt5_slate_fw-Debug/quick.app/Contents/MacOS/quick ...
      14:920 QML debugging is enabled. Only use this in a safe environment.
      16:595 hoverEnterEvent: QHoverEvent(HoverEnter, 0x7ffee02a1c80)
      16:596 hoverMoveEvent: QPointF(49.1484,6.86328)
      16:598 hoverMoveEvent: QPointF(49.1484,6.86328)
      16:601 hoverMoveEvent: QPointF(57.5156,19.0352)
      16:610 hoverMoveEvent: QPointF(65.5742,30.0234)
      16:617 hoverMoveEvent: QPointF(72.8984,41.0117)
      16:625 hoverMoveEvent: QPointF(80.6484,50.875)
      16:631 hoverMoveEvent: QPointF(80.6484,50.875)
      16:634 hoverMoveEvent: QPointF(89.7773,62.2852)
      16:660 hoverMoveEvent: QPointF(118.258,97.7266)
      16:664 hoverMoveEvent: QPointF(118.258,97.7266)
      

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes