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

QML scene shown inside QQuickWidget doesn't get QHoverEvent when cursor leaves the widget

    XMLWordPrintable

    Details

    • Commits:
      37d25a5112cdf13620715c03d6bdbd1bc3cde515

      Description

      QML scene displayed with QQuickWidget doesn't get QHoverEvent when cursor leaves the widget.

      In the example below the QML rectangle supposed to become red when cursor enters rectangle, and green when it leaves. It doesn't happen when the scene is displayed with QQuickWidget, though it works as intended when the scene is displayed with QWidget::createWindowContainer(...).

      === Example.qml ===

      import QtQuick 2.3
      
      Rectangle {
          color: mouseArea.containsMouse ? "red" : "green"
          MouseArea {
              id: mouseArea
              hoverEnabled: true
              anchors.fill: parent
          }
      }
      

      === main.cpp ===

      #include <QApplication>
      #include <QQuickView>
      #include <QQuickWindow>
      #include <QQuickWidget>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          // This approach, commented out, works as intended
          /*
          QQuickView *v = new QQuickView(QUrl("qrc:/Example.qml"));
          v->setResizeMode(QQuickView::SizeRootObjectToView);
          QWidget *w = QWidget::createWindowContainer(v);
          w->show();
          */
      
      
          // This way the MouseArea does not get an event
          // when cursor leaves the widget.
      
          QQuickWidget *w = new QQuickWidget(QUrl("qrc:/Example.qml"));
          w->setResizeMode(QQuickWidget::SizeRootObjectToView);
          w->show();
      
          return app.exec();
      }
      

      My current workaround, without touching Qt source code, is to install event filter on QQuickWidget, intercept events with type QEvent::Leave and, once caught, manually send QMouseMove event with QEvent::MouseMove type and ( – 1, – 1) coordinate to the off-screen window of the widget (that I get as widget->rootItem()->window()).

        Attachments

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

          Activity

            People

            Assignee:
            andysh Andy Shaw
            Reporter:
            birdofprey Sergey Pogodin
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes