[Interest] hi-res drawing on Windows

John Weeks john at wavemetrics.com
Thu Feb 5 23:29:26 CET 2015


Is there a comprehensive overview of drawing for monitors at various resolutions on Windows?

I am trying to get our application to work correctly on a hi-res monitor on Windows. In particular, I have a QToolButton-derived class that makes a button that is just the icon, with no visible frame. It overrides sizeHint(), maximumSize() and paintEvent() to do this. Instances of the button are given icons from PNG resources that have  both standard and "@2x" versions.

One point of this class is to size the button based on the size of the icon. Thus, sizeHint() and maximumSize() both return iconSize(). In the paintEvent(), I get the icon out of the button using icon(), get the QWindow for the window hosting the button and then use QIcon::pixmap(QWindow *, iconSize(), ...) to get the appropriate QPixmap to draw.

On Macintosh this works great. On my 5k iMac I get the correct size and hi-res pixmap. Slide the window over to my external standard-res monitor and it redraws with the standard res pixmap.

On Windows, I don't have a hi-res monitor. I'm faking it by setting "Change the size of all items" to Larger 150%. That's another way to say, "Make my large monitor small" :) Not ideal, and it's not 2x, so I don't really expect the 2x icons. What I DO expect is the QWindow::devicePixelRatio() might return 1.5, but all I get is 1.0 at all settings of "size of all items".

I found this:
http://doc-snapshot.qt-project.org/qt5-5.4/highdpi.html

Since I'm on Windows 8.1 I should be in "Per-Monitor DPI Aware" mode. It seems like I shouldn't have to intervene in order to get resolution-independent pixel drawing.

If I do this before creating my QApplication instance:
qputenv("QT_DEVICE_PIXEL_RATIO", "2")
then I get 2.0 from devicePixelRatio(), as expected. I also get my hi-res icons.

If I do this instead:
qputenv("QT_DEVICE_PIXEL_RATIO", "1.5")
then devicePixelRatio returns 1.0, not 1.5.

And it doesn't seem like I should have to set this myself, anyway.

Thanks for any insight you might be able to offer!

-John Weeks




More information about the Interest mailing list