Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Return appropriate value for Qt automatic scaling
Browse files Browse the repository at this point in the history
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 12, 2018
1 parent ab322f1 commit c412ddf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ubuntumirclient/screen.cpp
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/ubuntumirclient/screen.h
Expand Up @@ -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; }
Expand Down

0 comments on commit c412ddf

Please sign in to comment.