25

I am developing on a 4k monitor and its a pain...

Finally I managed to set up QtDesigner and then ecountered this issue:

When you use QT_AUTO_SCREEN_SCALE_FACTOR=1 and compile an app with radiobutton and other basic widgets, it looks scaled on a 4k screen. Otherwise the dimensions of controls are correct and as expected, its just not sharp, but rather pixelated.

I am running on Windows 10 Home 64bit on 4k screen with 200% DPI zoom, using Qt 5.6 RC msvc2015 64bit and tried with achieving the same results using

QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

dcreenshot

If I use

QGuiApplication::setAttribute(Qt::AA_DisableHighDpiScaling);

the controls are sharp, text size is ok BUT all dimensions are much smaller.

How do I make controls sharp on high DPI screen?

michnovka
  • 2,880
  • 3
  • 26
  • 58
  • 1
    I do that either with stylesheet for widgets: http://stackoverflow.com/questions/34407001/qt-and-high-dpi-screens/34408516#34408516 or I use QML UI. – Alexander V Mar 01 '16 at 04:52
  • 1
    I read your reply before, but this does not seem to me as the native high dpi support everybody talked about. Id expect this to be automatic, why are the controls pixelated and not rendered sharply? If this is the standard behaviour, how can it be recommended by all official sources? – michnovka Mar 01 '16 at 05:21
  • Having a considerably large code base we don't rush to switch to Qt 5.6 and consider 5.5 stable enough and you basically just discovered how much advantage one can get AA_EnableHighDpiScaling mode. If you used QML that would be very different but sharp. Mind scale QML Rectangle attribute then. A bit more to read on https://doc-snapshots.qt.io/qt5-5.6/highdpi.html – Alexander V Mar 01 '16 at 05:24
  • 1
    It is not true that using QML will solve the issue on Windows. I am developing an app in 5.6 and on Mac everything is perfect (thx to the OS) on Windows...I don't even want to start...enabling QApplication::setAttribute(Qt::AA_EnableHighDpiScaling) just for Windows solves some of the problems, but it actually introduces a whole set of new problems when you start using multiple monitors with different resolutions. When Qt people say 5.6 is supporting HDPI it is just lie unfortunately. There are many many issues and bug reports and it doesn't really look like that they gonna be fixed soon. – Silex Dec 16 '16 at 22:33
  • Here is an article which might help: http://vicrucann.github.io/tutorials/osg-qt-high-dpi/ – Silex Dec 16 '16 at 22:36
  • I recommend you update to Qt 5.8: the HiDPI features are just introduced in 5.6, and some of them had bugs. – Tatsuyuki Ishi Mar 07 '17 at 08:11
  • 1
    Can you try setAttribute(Qt::AA_UseHighDpiPixmaps); – Petr Mar 21 '17 at 12:48
  • If you are not forced to use native look-n-feel I propose you to use `Fustion` style for your app. It looks cool and has good high dpi support. – Dmitry Sazonov Dec 19 '17 at 12:29

3 Answers3

7

As Qt documentation says:

Use QT_AUTO_SCREEN_SCALE_FACTOR to enable platform plugin controlled per-screen factors.
QT_SCREEN_SCALE_FACTORS to set per-screen factors.
QT_SCALE_FACTOR to set the application global scale factor.

You can try doing what Qt Creator is doing:

static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO";
if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO)
        && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
        && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
        && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) {
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
}

Basically important thing is the last line QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);.

Ribtoks
  • 6,634
  • 1
  • 25
  • 37
3

Here is what was working for me. You can set DPIawareness manually by giving a command line option at the instanciation of the QApplication.

The official documentation is here https://doc.qt.io/qt-5/highdpi.html (section DPI awareness).

According to the documentation, you can set the application to DPI Unaware (thus it will automatically scale but display will be blurred), or to System DPI Aware or to Per-Monitor Aware.

Here is a minimal example code for the instanciation of the QApplication to force High DPI, choose other value than 1 (0 or 2) to enable DPIUnaware or Per Monitor DPI Aware:

int main() 
{
   int argc = 3;
   char*argv[] = {(char*)"Appname", (char*)"--platform", (char*)"windows:dpiawareness=1";
   (void) new QApplication(argc, argv);
}
Pat. ANDRIA
  • 2,330
  • 1
  • 13
  • 27
2

With QT_AUTO_SCREEN_SCALE_FACTOR, the point size of the fonts are not changed, they're just scaled up from their original pixels, so they will never be smooth, only more bumpy.

Ref: http://doc.qt.io/qt-5.6/highdpi.html#high-dpi-support-in-qt "This will not change the size of point sized fonts"

You need to use QT_SCALE_FACTOR instead to rescale your app, not just rescale its pixels.

G Huxley
  • 1,130
  • 14
  • 19