Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get physical screen size in Qt

Tags:

People also ask

How do I screen size in Qt?

Qt includes a very simple method to get the size of the screen (width and height). Here it is: QSize size = qApp->screens()[0]->size(); Note that this function works perfectly in Android and iOS too.

What is Qt_ scale_ factor?

QT_SCALE_FACTOR [numeric] defines a global scale factor for the whole application, including point-sized fonts. QT_SCREEN_SCALE_FACTORS [list] specifies scale factors for each screen. This won't change the size of point-sized fonts.


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.