[Interest] hi-res drawing on Windows

2015-02-05 Thread John Weeks
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

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] hi-res drawing on Windows

2015-02-05 Thread Jason H
I don't know why that variable exists. It's useless as far as I can tell. Maybe 
it means that you are being scaled?

I use Screen.pixelDensity. Which varies as you think it should, but is spec'd 
in px per mm, not DPI.

That pixelRatio is either 1 or 0, I don't think it is ever in between. In 
theory on a 2x device the pixelDenisty will be 2x the 1x.
Meanwhile pixel ratio is:
old (10yr) monitor: 4.x
Samsung Note 2: 10.x
Moto X: 16.x



 Sent: Thursday, February 05, 2015 at 5:29 PM
 From: John Weeks j...@wavemetrics.com
 To: interest@qt-project.org interest@qt-project.org
 Subject: [Interest] hi-res drawing on Windows

 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
 
 ___
 Interest mailing list
 Interest@qt-project.org
 http://lists.qt-project.org/mailman/listinfo/interest
 
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] hi-res drawing on Windows

2015-02-05 Thread John Weeks

 On Feb 5, 2015, at 3:03 PM, Jason H jh...@gmx.com wrote:
 int
 That pixelRatio is either 1 or 0, I don't think it is ever in between.

Well, during development of my button class, when I had bugs :) I saw QPixmap 
return devicePixelRatio between 1.0 and 2.0. Maybe that's just QPixmap, though.

-John Weeks

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest