diff options
author | David Edmundson <davidedmundson@kde.org> | 2022-12-06 12:31:54 +0000 |
---|---|---|
committer | David Edmundson <davidedmundson@kde.org> | 2023-05-11 12:57:13 +0300 |
commit | 1314592f41abecb6f1140d3bfe39bba8a2c4ea7e (patch) | |
tree | 35a751f189577949e414580574d114ff02f96549 | |
parent | 1257e1d3b264a2a358408b2bf8ad3814bdf7c1aa (diff) | |
download | qtdeclarative-1314592f41abecb6f1140d3bfe39bba8a2c4ea7e.tar.gz |
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 <aleixpol@kde.org>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 33 | ||||
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 9 |
2 files changed, 18 insertions, 24 deletions
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(); |