diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 0eb53df443e..2c2d8332093 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1032,6 +1032,7 @@ bool QGuiApplication::notify(QObject *object, QEvent *event) } #endif + QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(qobject_cast(object), event); return QCoreApplication::notify(object, event); } @@ -1053,6 +1054,20 @@ bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEvent return QCoreApplication::compressEvent(event, receiver, postedEvents); } +void QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event) +{ + if (!window) + return; + QPlatformWindow *platformWindow = window->handle(); + if (!platformWindow) + return; + // spontaneous events come from the platform integration already, we don't need to send the events back + if (event->spontaneous()) + return; + // let the platform window do any handling it needs to as well + platformWindow->windowEvent(event); +} + bool QGuiApplicationPrivate::processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result) { return window->nativeEvent(eventType, message, result); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index c0cee518321..35bf8570eae 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -129,6 +129,8 @@ public: static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result); + static void sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event); + static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment) { if (!(alignment & Qt::AlignHorizontal_Mask)) diff --git a/src/gui/kernel/qplatformwindow_qpa.cpp b/src/gui/kernel/qplatformwindow_qpa.cpp index d5f0277ccd1..b36a2771f3d 100644 --- a/src/gui/kernel/qplatformwindow_qpa.cpp +++ b/src/gui/kernel/qplatformwindow_qpa.cpp @@ -310,6 +310,18 @@ bool QPlatformWindow::setMouseGrabEnabled(bool grab) return false; } +/*! + Reimplement this method to be able to do any platform specific event + handling. All events for window() are passed to this function before being + sent to QWindow::event(). + + The default implementation is empty and does nothing with \a event. +*/ +void QPlatformWindow::windowEvent(QEvent *event) +{ + Q_UNUSED(event); +} + /*! \class QPlatformWindow \since 4.8 diff --git a/src/gui/kernel/qplatformwindow_qpa.h b/src/gui/kernel/qplatformwindow_qpa.h index a2b6bcb508c..31b14ca97d7 100644 --- a/src/gui/kernel/qplatformwindow_qpa.h +++ b/src/gui/kernel/qplatformwindow_qpa.h @@ -113,6 +113,8 @@ public: virtual bool setKeyboardGrabEnabled(bool grab); virtual bool setMouseGrabEnabled(bool grab); + virtual void windowEvent(QEvent *event); + protected: QScopedPointer d_ptr; private: diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index c560dba1b7c..e82f5c15312 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -2992,6 +2992,8 @@ bool QApplication::notify(QObject *receiver, QEvent *e) d->checkReceiverThread(receiver); #endif + QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(qobject_cast(receiver), e); + // capture the current mouse/keyboard state if(e->spontaneous()) { if (e->type() == QEvent::MouseButtonPress