diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index a05f0d69d54..8c13aff577d 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -3264,6 +3264,14 @@ void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::E const bool wasExposed = p->exposed; p->exposed = e->isExposed && window->screen(); + // We expect that the platform plugins send DevicePixelRatioChange events. + // As a fail-safe make a final check here to make sure the cached DPR value is + // always up to date before sending the expose event. + const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio(); + if (dprWasChanged) + qWarning() << "The cached device pixel ratio value was stale on window expose. " + << "Please file a QTBUG which explains how to reproduce."; + // We treat expose events for an already exposed window as paint events if (wasExposed && p->exposed && shouldSynthesizePaintEvents) { QPaintEvent paintEvent(e->region); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 3c9194cb6ed..0aeb1514057 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1359,8 +1359,9 @@ qreal QWindow::devicePixelRatio() const /* Updates the cached devicePixelRatio value by polling for a new value. Sends QEvent::DevicePixelRatioChange to the window if the DPR has changed. + Returns true if the DPR was changed. */ -void QWindowPrivate::updateDevicePixelRatio() +bool QWindowPrivate::updateDevicePixelRatio() { Q_Q(QWindow); @@ -1371,11 +1372,12 @@ void QWindowPrivate::updateDevicePixelRatio() platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q) : q->screen()->devicePixelRatio(); if (newDevicePixelRatio == devicePixelRatio) - return; + return false; devicePixelRatio = newDevicePixelRatio; QEvent dprChangeEvent(QEvent::DevicePixelRatioChange); QGuiApplication::sendEvent(q, &dprChangeEvent); + return true; } Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state) diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index 96beb17becf..7b1aad4838c 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -89,7 +89,7 @@ public: void setAutomaticPositionAndResizeEnabled(bool a) { positionAutomatic = resizeAutomatic = a; } - void updateDevicePixelRatio(); + bool updateDevicePixelRatio(); static QWindowPrivate *get(QWindow *window) { return window->d_func(); }