I have a Qt Widgets application using Qt styleSheet for the appearance of the application. We want to add support for high-resolution displays, as the application looks very small on them. So the first step was this:
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
This does most of the work and the application window is large enough. The only remaining problem is the resolution of the images used in the stylesheet.
Let's say that we have:
QCheckBox::indicator::unchecked { image: url(:/res/checkbox_off.png); } MainWindow QFrame { background-image: url(:/res/background.png); }
When using high DPI scaling, these images are scaled accordingly, which is a problem. For high DPI, I prefer to use higher resolution images so that they look as clear as possible.
As expected, the naive approach of simply presenting images in higher resolution does not work - it makes images and controls twice as large (both on low and high DPI screens).
The Qt documentation on QImageReader claims that
The high-resolution version is marked with the suffix @ 2x on the base name. When reading an image, the pixel ratio of the device will be set to 2.
However, I provided these resources with a double resolution, added them to the qrc file, but the displayed images still match on the device with pixel_ratio of 3.
Are there any other steps necessary for this automatic image loading to work with styles?
source share