Android: Fix UI is scaled smaller than before

The 413593183b patch changed the way
how the display metrics are retrieved. By doing so, it was found that
the previous way retrieved the scaledDensity always equal to density.
It is intentional for scaledDensity to be dependent on the font scale
chosen by the user. However, this change altered not only the font scale
but also the layout. This patch will make the layout dependent on the
density instead of the scaledDensity and normalize the way the display
metrics are retrieved among Android versions.
Currently, the fontScale is ignored, QTBUG-109566 will track future
developments.

Fixes: QTBUG-109026
Pick-to: 6.5 6.4 6.2 5.15
Change-Id: I6adacd17583cbe9bee368af35c50b780872ab222
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Samuel Mira 2022-12-21 15:39:44 +02:00
parent e62a3383fb
commit 99893a914a
2 changed files with 7 additions and 15 deletions

View File

@ -109,11 +109,6 @@ public class QtLayout extends ViewGroup
maxWidth = maxMetrics.widthPixels;
maxHeight = maxMetrics.heightPixels;
density = appMetrics.density;
xdpi = appMetrics.xdpi;
ydpi = appMetrics.ydpi;
scaledDensity = appMetrics.scaledDensity;
} else {
// after API 30 use getCurrentWindowMetrics for application metrics
// getMaximumWindowMetrics for the screen metrics
@ -138,17 +133,14 @@ public class QtLayout extends ViewGroup
maxWidth = maxMetrics.getBounds().width();
maxHeight = maxMetrics.getBounds().height();
final Resources resources = activity.getResources();
final Configuration configuration = resources.getConfiguration();
density = configuration.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;
final DisplayMetrics displayMetrics = resources.getDisplayMetrics();
xdpi = displayMetrics.xdpi;
ydpi = displayMetrics.ydpi;
density = displayMetrics.density;
scaledDensity = displayMetrics.scaledDensity;
}
final DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
xdpi = displayMetrics.xdpi;
ydpi = displayMetrics.ydpi;
density = displayMetrics.density;
scaledDensity = displayMetrics.scaledDensity;
float refreshRate = display.getRefreshRate();
if ((appWidth > appHeight) != (w > h)) {

View File

@ -476,7 +476,7 @@ static const int androidLogicalDpi = 72;
QDpi QAndroidPlatformScreen::logicalDpi() const
{
qreal lDpi = QtAndroid::scaledDensity() * androidLogicalDpi;
qreal lDpi = QtAndroid::pixelDensity() * androidLogicalDpi;
return QDpi(lDpi, lDpi);
}