MCPcopy Create free account
hub / github.com/SeaEpoch/MouseClick / emulateLeaveEvent

Function emulateLeaveEvent

src/mainwindow.cpp:31–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29};
30
31static inline void emulateLeaveEvent(QWidget* widget)
32{
33 Q_ASSERT(widget);
34 if (!widget) {
35 return;
36 }
37 QTimer::singleShot(0, widget, [widget]() {
38#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
39 const QScreen* screen = widget->screen();
40#else
41 const QScreen* screen = widget->windowHandle()->screen();
42#endif
43 const QPoint globalPos = QCursor::pos(screen);
44 if (!QRect(widget->mapToGlobal(QPoint{0, 0}), widget->size()).contains(globalPos)) {
45 QCoreApplication::postEvent(widget, new QEvent(QEvent::Leave));
46 if (widget->testAttribute(Qt::WA_Hover)) {
47 const QPoint localPos = widget->mapFromGlobal(globalPos);
48 const QPoint scenePos = widget->window()->mapFromGlobal(globalPos);
49 static constexpr const auto oldPos = QPoint{};
50 const Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
51#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
52 const auto event =
53 new QHoverEvent(QEvent::HoverLeave, scenePos, globalPos, oldPos, modifiers);
54 Q_UNUSED(localPos);
55#elif (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
56 const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, globalPos, oldPos, modifiers);
57 Q_UNUSED(scenePos);
58#else
59 const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, oldPos, modifiers);
60 Q_UNUSED(scenePos);
61#endif
62 QCoreApplication::postEvent(widget, event);
63 }
64 }
65 });
66}
67
68
69MainWindow::MainWindow(QWidget* parent)

Callers 1

windowInitMethod · 0.85

Calls 1

windowMethod · 0.80

Tested by

no test coverage detected