Add catch-all DPR update to expose event handling

The platform plugin should already DPR (or DPI) change
events, however if that does not happen we update in
the expose event as well as a last resort to make sure
the window's DPR value is in sync.

Also print a warning and ask for a bug report.

Pick-to: 6.0
Change-Id: Ibb144f163281a28216c2fa3353ed50237e91ce25
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
(cherry picked from commit 5f1c29376c02f722450f6bf1aa5f0647601e0e59)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Morten Sørvig 2023-08-21 16:19:00 +02:00 committed by Qt Cherry-pick Bot
parent 6ab5ec5b4a
commit 114c8eb7a5
3 changed files with 13 additions and 3 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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(); }