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
color: mouseArea.containsMouse ? "red" : "green"
=== main.cpp ===
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"));
QWidget *w = QWidget::createWindowContainer(v);
// This way the MouseArea does not get an event
// when cursor leaves the widget.
QQuickWidget *w = new QQuickWidget(QUrl("qrc:/Example.qml"));
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()).