PDA

View Full Version : how to get screen pixel size?



kodiak
25th August 2008, 13:44
Hi,

Does anyone know how to get pixel size with Qt?

Thanks

wysota
25th August 2008, 15:30
Do you mean the resolution? Take a look at QDesktopWidget and what it offers.

kodiak
25th August 2008, 16:15
wysota, I just need a pixel or screen width and height in millimeters. I have to draw symbols at the same dimension on defferent screens and resolutions.

pherthyl
25th August 2008, 18:13
wysota, I just need a pixel or screen width and height in millimeters. I have to draw symbols at the same dimension on defferent screens and resolutions.


All you can do is use the DPI that the system gives you to convert to a physical unit and then draw based on that. However, that DPI is not correct on most monitors, so drawing something to exactly the same physical size is practically impossible.

wysota
25th August 2008, 22:23
The pixel size is in its nature resolution independent (as opposed to point size, or vice versa - in that case revert everything I say here), so if you count everything in logical pixels (and not points) you should get consistent sizes (this especially applies to fonts).

kodiak
26th August 2008, 08:57
There is solution in QPaintDevice class. Methods widthMM() and heightMM() returns what I have been looking for!

pherthyl
26th August 2008, 18:59
There is solution in QPaintDevice class. Methods widthMM() and heightMM() returns what I have been looking for!

Yes, they return a measurement in millimeters, but you can't actually trust the value that it gives you. Sure it'll be sort of correct, but if you verify it with a ruler it won't match up (unless your monitor has a perfect DPI setting, which is very unlikely, and most people don't).