From 1314592f41abecb6f1140d3bfe39bba8a2c4ea7e Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Tue, 6 Dec 2022 12:31:54 +0000 Subject: QQuickWindow track changes via DevicePixelRatioChange event Qt core gained a new event on the window when the dpr changes. This is important as the window DPR can differ from the screen device pixel ratio, it also allows us to get rid of one level of the screen connection tracking. Fixes: QTBUG-113236 Change-Id: I43f50a0ef98653553ea177dc72e1522036452496 Reviewed-by: Aleix Pol Gonzalez Reviewed-by: Qt CI Bot --- src/quick/items/qquickwindow.cpp | 33 +++++++++++---------------------- src/quickwidgets/qquickwidget.cpp | 9 +++++++-- 2 files changed, 18 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 325989a5d6..a9813d5187 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -398,6 +398,7 @@ void QQuickWindow::physicalDpiChanged() d->lastReportedItemDevicePixelRatio = newPixelRatio; if (d->contentItem) updatePixelRatioHelper(d->contentItem, newPixelRatio); + d->forcePolish(); } void QQuickWindow::handleFontDatabaseChanged() @@ -406,23 +407,6 @@ void QQuickWindow::handleFontDatabaseChanged() d->pendingFontUpdate = true; } -void QQuickWindow::handleScreenChanged(QScreen *screen) -{ - Q_D(QQuickWindow); - // we connected to the initial screen in QQuickWindowPrivate::init, but the screen changed - disconnect(d->physicalDpiChangedConnection); - if (screen) { - physicalDpiChanged(); - // When physical DPI changes on the same screen, either the resolution or the device pixel - // ratio changed. We must check what it is. Device pixel ratio does not have its own - // ...Changed() signal. Reconnect, same as in QQuickWindowPrivate::init. - d->physicalDpiChangedConnection = connect(screen, &QScreen::physicalDotsPerInchChanged, - this, &QQuickWindow::physicalDpiChanged); - } - - d->forcePolish(); -} - void forcePolishHelper(QQuickItem *item) { if (item->flags() & QQuickItem::ItemHasContents) { @@ -434,6 +418,13 @@ void forcePolishHelper(QQuickItem *item) forcePolishHelper(items.at(i)); } +void QQuickWindow::handleScreenChanged(QScreen *screen) +{ + Q_D(QQuickWindow); + Q_UNUSED(screen); + d->forcePolish(); +} + /*! Schedules polish events on all items in the scene. */ @@ -746,12 +737,8 @@ void QQuickWindowPrivate::init(QQuickWindow *c, QQuickRenderControl *control) q, &QQuickWindow::handleFontDatabaseChanged); - if (QScreen *screen = q->screen()) { + if (q->screen()) { lastReportedItemDevicePixelRatio = q->effectiveDevicePixelRatio(); - // if the screen changes, then QQuickWindow::handleScreenChanged disconnects - // and connects to the new screen - physicalDpiChangedConnection = QObject::connect(screen, &QScreen::physicalDotsPerInchChanged, - q, &QQuickWindow::physicalDpiChanged); } QSGContext *sg; @@ -1555,6 +1542,8 @@ bool QQuickWindow::event(QEvent *event) d->inheritPalette(QGuiApplication::palette()); if (d->contentItem) QCoreApplication::sendEvent(d->contentItem, event); + case QEvent::DevicePixelRatioChange: + physicalDpiChanged(); default: break; } diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 8a472a4f0a..2197ab834d 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -1681,15 +1681,20 @@ bool QQuickWidget::event(QEvent *e) QScreen *newScreen = screen(); if (d->offscreenWindow) d->offscreenWindow->setScreen(newScreen); - + break; + } + case QEvent::DevicePixelRatioChange: if (d->useSoftwareRenderer || d->outputTexture) { // This will check the size taking the devicePixelRatio into account // and recreate if needed. createFramebufferObject(); d->render(true); } + if (d->offscreenWindow) { + QEvent dprChangeEvent(QEvent::DevicePixelRatioChange); + QGuiApplication::sendEvent(d->offscreenWindow, &dprChangeEvent); + } break; - } case QEvent::Show: case QEvent::Move: d->updatePosition(); -- cgit v1.2.1