High-DPI Support in Qt Quick Controls 2 | Qt Quick Controls 2 5.9

Qt 5.9 | Qt Quick Controls 2 | High-DPI Support in Qt Quick Controls 2

Qt 5.9.4 Reference Documentation

# High-DPI Support in Qt Quick Controls 2

Qt Quick Controls 2 support Qt's cross-platform high-DPI scaling introduced in Qt 5.6. The feature is opt-in, and can be enabled by setting the `Qt::AA_EnableHighDpiScaling` application attribute in C++ before QGuiApplication is constructed:

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>

      int main(int argc, char *argv[])
      {
          QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // <--
          QGuiApplication app(argc, argv);
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
          return app.exec();
      }

Alternatively, an environment variable `QT_AUTO_SCREEN_SCALE_FACTOR=1` can be set to enable automatic high-DPI scaling.

Warning: Qt Quick Controls 1.x are not compatible with Qt's automatic high-DPI scaling. There is currently no available solution for high-DPI support in applications wishing to mix Qt Quick Controls and Qt Quick Controls 2.

## Related Information

- High DPI Displays
- Scalability