Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.12.3
-
None
-
macOS 10.14.5
MacBook Pro
Description
In the (simplified) application below, the cursor should be blank when the window is active, which means you should never see an arrow cursor. However, alt-tabbing back and forth shows that the cursor shape is sometimes set to Qt::ArrowShape.
It's easiest to reproduce the issue when alt-tabbing through the complete list of open applications and back to the Qt application.
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickItem> #include <QQuickWindow> class CustomItem : public QQuickItem { Q_OBJECT public: CustomItem() : mContainsMouse(false) { setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); setFocus(true); } void updateWindowCursorShape() { window()->setCursor(QCursor(mContainsMouse ? Qt::BlankCursor : Qt::ArrowCursor)); } bool containsMouse() const { return mContainsMouse; } void setContainsMouse(bool containsMouse) { qDebug() << "setContainsMouse:" << containsMouse; if (containsMouse == mContainsMouse) return; mContainsMouse = containsMouse; updateWindowCursorShape(); } void mousePressEvent(QMouseEvent *event) override { qDebug() << "mousePressEvent:" << event; QQuickItem::mousePressEvent(event); setContainsMouse(true); } void mouseMoveEvent(QMouseEvent *event) override { qDebug() << "mouseMoveEvent:" << event; QQuickItem::mouseMoveEvent(event); setContainsMouse(true); } void hoverEnterEvent(QHoverEvent *event) override { qDebug() << "hoverEnterEvent:" << event; QQuickItem::hoverEnterEvent(event); setContainsMouse(true); } void hoverMoveEvent(QHoverEvent *event) override { qDebug() << "hoverMoveEvent:" << event->posF(); QQuickItem::hoverMoveEvent(event); setContainsMouse(true); } void hoverLeaveEvent(QHoverEvent *event) override { qDebug() << "hoverLeaveEvent:" << event; QQuickItem::hoverLeaveEvent(event); setContainsMouse(false); } void focusInEvent(QFocusEvent *event) override { qDebug() << "focusInEvent:" << event; QQuickItem::focusInEvent(event); setContainsMouse(true); } void focusOutEvent(QFocusEvent *event) override { qDebug() << "focusOutEvent:" << event; QQuickItem::focusOutEvent(event); setContainsMouse(false); } private: bool mContainsMouse; }; 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"
main.qml
import QtQuick 2.0 import QtQuick.Window 2.0 import App 1.0 Window { id: root width: 640 height: 480 visible: true CustomItem { anchors.fill: parent } }
When setting QT_MESSAGE_PATTERN to
%{time mm:ss:zzz} %{message}
I see the following output when alt-tabbing back into the application:
42:31:427 hoverLeaveEvent: QHoverEvent(HoverLeave, 0x7ffee3450d30) 42:31:427 setContainsMouse: false
This could suggest that HoverLeave is being sent instead of HoverEnter when the window becomes active.