I'km working in Qt, i need help to get the physical size of the screen (monitor),
In Qt one can get a QDesktopWidget
from QApplication
, I mean:
QDesktopWidget *mydesk = QApplication::desktop();
The QDesktopwidget
has some methods to get the resolution in pixels and some to get the the size in milimethers:
mydesk-> widthMM(); mydesk->heightMM();
However, this does not correspond to the physical size, when I measure my screen with a ruler, there is a considerable difference.
Also one can get the DPI measurement and calculate the size of the screen:
mydesk->physicalDpiX(); mydesk->physicalDpiY();
double Winches = (double)mydesk.width() / (double)mydesk.physicalDpiX();
double Hinches = (double)mydesk.Height() / (double)mydesk.physicalDpiY();
where mydesk.width()
and mydesk.height()
give the size in pixels(resolution)
However the measurement is also wrong and very close to mydesk.widthMM()
and mydesk.heightMM()
Also I have triyed mydesk.logicalDpiX()
and it has similar results.
Best Answer
Here is my (quick and dirty) example. It seems to work for me and I hope it works for you. I'm assuming you can take care of main.cpp on your own. I did this on a MacBook Air 11.6" and substituted a picture of a dime for the USA icon included with OS X: