From d870ea28656a2155c39a1aabefa1c56871a017e4 Mon Sep 17 00:00:00 2001 From: Andreas Hartmetz Date: Thu, 14 Jan 2016 00:15:37 +0100 Subject: Rerender natively rendered text items when DPI scaling changes. The whole purpose of native rendering is to optimize precisely for a given pixel grid. DPI scaling can change when either settings of the current screen are changed, or when the window is moved to a different screen. Details: - add an ItemDevicePixelRatioHasChanged item change event - detect DPI scaling changes by watching screen (identity) and screen config changes - when DPI scaling changes, recursively send an ItemDevicePixelRatioHasChanged signal to all items with content - when a natively renderet TextItem catches such an event, call updateLayout() which automatically picks up the new logical DPI Task-number: QTBUG-49019 Change-Id: I9f4f8d1a7f2c172ed26c276294ab143161c4a48b Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/quick/items/qquicktext.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/quick/items/qquicktext.cpp') diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 3aec464958..aa8f04e55d 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -1455,7 +1455,8 @@ void QQuickText::itemChange(ItemChange change, const ItemChangeData &value) { Q_D(QQuickText); Q_UNUSED(value); - if (change == ItemAntialiasingHasChanged) { + switch (change) { + case ItemAntialiasingHasChanged: if (!antialiasing()) d->font.setStyleStrategy(QFont::NoAntialias); else @@ -1463,6 +1464,22 @@ void QQuickText::itemChange(ItemChange change, const ItemChangeData &value) d->implicitWidthValid = false; d->implicitHeightValid = false; d->updateLayout(); + break; + + case ItemDevicePixelRatioHasChanged: + if (d->renderType == NativeRendering) { + // Native rendering optimizes for a given pixel grid, so its results must not be scaled. + // Text layout code respects the current device pixel ratio automatically, we only need + // to rerun layout after the ratio changed. + // Changes of implicit size should be minimal; they are hard to avoid. + d->implicitWidthValid = false; + d->implicitHeightValid = false; + d->updateLayout(); + } + break; + + default: + break; } QQuickItem::itemChange(change, value); } -- cgit v1.2.3