Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.4.0
-
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
For Gerrit Dashboard: QTBUG-45557 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
111733,2 | Pass enter and leave events to the offscreen window. | 5.5 | qt/qtdeclarative | Status: ABANDONED | +2 | 0 |
142748,12 | QQuickWidget: pass enter and leave events to the offscreen window | 5.9 | qt/qtdeclarative | Status: MERGED | +2 | 0 |