Permalink
Browse files

Return appropriate value for Qt automatic scaling

Previously, QtUbuntu did not return the appropriate values for QtQuick2
scaling. This meant that developers would need to add some boilerplate
to their main.cpp or a shell script which set the QT_SCALE_FACTOR
environment variable by dividing the GRID_UNIT_PIXELS value on the
platform. This change makes QtUbuntu return QScreen::pixelDensity(), the
value which Qt uses to determine the scale factor by itself. The
constant of 96 was chosen since it appears to give amicable results with
the apps I've tested and is in line with the X QPA's pixelDensity()
equation.

Now, apps which specify sizes in pixels (by just putting an integer in
their width or height of widgets) will receive an integer scale factor.
For example, an item with a width of 100 pixels becomes 200 pixels wide
when run.

Fixes ubports/ubuntu-touch#841
  • Loading branch information...
UniversalSuperBox committed Sep 11, 2018
1 parent ab322f1 commit c412ddf8942fde6911115c7f725e42c71c2b6b58
Showing with 6 additions and 0 deletions.
  1. +5 −0 src/ubuntumirclient/screen.cpp
  2. +1 −0 src/ubuntumirclient/screen.h
@@ -228,6 +228,11 @@ void UbuntuScreen::setAdditionalMirDisplayProperties(float scale, MirFormFactor
}
}

qreal UbuntuScreen::pixelDensity() const
{
return qMax(1, qRound(logicalDpi().first / 96));
}

QDpi UbuntuScreen::logicalDpi() const
{
if (mDpi > 0) {
@@ -41,6 +41,7 @@ class UbuntuScreen : public QObject, public QPlatformScreen
QRect availableGeometry() const override { return mGeometry; }
QSizeF physicalSize() const override { return mPhysicalSize; }
qreal devicePixelRatio() const override { return mDevicePixelRatio; }
qreal pixelDensity() const override;
QDpi logicalDpi() const override;
Qt::ScreenOrientation nativeOrientation() const override { return mNativeOrientation; }
Qt::ScreenOrientation orientation() const override { return mNativeOrientation; }

0 comments on commit c412ddf

Please sign in to comment.