Get physical screen size in Qt
The following method worked for me to get accurate physical size of my screen in mm.
QSizeF screenSize = QGuiApplication::primaryScreen()->physicalSize();
However, in Qt documentation I found the following sentence:
Depending on what information the underlying system provides the value might not be entirely accurate.
So it might not work for your system.
Related videos on Youtube

Hermandroid
Updated on August 07, 2020Comments
-
Hermandroid almost 3 years
I'km working in Qt, i need help to get the physical size of the screen (monitor),
In Qt one can get a
QDesktopWidget
fromQApplication
, 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()
andmydesk.height()
give the size in pixels(resolution)However the measurement is also wrong and very close to
mydesk.widthMM()
andmydesk.heightMM()
Also I have triyed
mydesk.logicalDpiX()
and it has similar results.