summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquickwindow.cpp33
-rw-r--r--src/quickwidgets/qquickwidget.cpp9
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();