Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

qt - Automatic rescaling of an application on high-dpi Windows platform?

I'm writing a Qt application that needs to run on high-dpi Windows (192dpi instead of 96dpi).

Unfortunately the Qt framework does not have support for high-dpi yet (at least on Windows), so my application and all its elements looks half the size it should.

Is there any way to force/simulate automatic upscaling of such apps by Windows?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Applications that use fixed coordinates and sizes will look small on high-DPI resolutions. Although even if using layouts there are some issues regarding element and font sizes and margins. Fortunately there is support for high-DPI displays since Qt 5.4 as there has been many high-DPI issue fixes.

An application on Windows can assume one of the following levels of "DPI Awareness" (From the Qt documentation) :

  • DPI Unaware: This level has been introduced in Windows-Vista. Windows will pretend to the application that it is running on a standard display of 96 DPI of 1920x1080 and scale the application accordingly. It is intended to accommodate older applications designed for low DPI displays. Some artifacts may result from this type of scaling.
  • System-DPI Aware: This level has been introduced in Windows-Vista. It differs from Per-Monitor DPI Aware only when multiple monitors are connected. Windows will calculate a scaling suitable for all connected monitors.
  • Per-Monitor DPI Aware: This level has been introduced in Windows 8.1. Windows does not perform any scaling at all.

Also it states that :

Qt applications by default are Per-Monitor DPI Aware on Windows 8.1 or System-DPI Aware on older versions of Windows. As of Qt 5.4, the level can be specified by passing a parameter to the platform plugin (see Using qt.conf):

<application> -platform windows:dpiawareness=0,1,2

You can read more information here.

In general to have a good UI on high-DPI displays, consider the following :

  • Use the latest version of Qt
  • Use layouts and avoid fixed sizes (unless you calculate scaling ratios on your own)
  • Make appropriate DPI-related settings depending on your application needs, for example set Qt::AA_UseHighDpiPixmaps attribute if you work with QPainter and pixmaps, or calculate a scaling ratio for adjusting certain element sizes in special situations.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...