Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between logicalDpiX and physicalDpiX in Qt?

Tags:

c++

dpi

fonts

qt

In the documentation of QPaintDevice (which all paintable-to entities derive from, such as QWidget, QPixmap, etc), there are two functions to receive the DPI of the device

int logicalDpiX() const;
int physicalDpiX() const;

int logicalDpiY() const;
int physicalDpiY() const;

The documentation says

The logicalDpiX() and logicalDpiY() functions return the horizontal and vertical resolution of the device in dots per inch. The physicalDpiX() and physicalDpiY() functions also return the resolution of the device in dots per inch, but note that if the logical and physical resolution differ, the corresponding QPaintEngine must handle the mapping. Finally, the colorCount() function returns the number of different colors available for the paint device.

Despite this description, I still don't understand what the purpose of the difference is. Can someone please shed some light on this?

like image 691
Johannes Schaub - litb Avatar asked May 15 '13 09:05

Johannes Schaub - litb


People also ask

What is logical DPI?

Logical dots per inch are used to convert font and user interface elements from point sizes to pixel sizes, and might be different from the physical dots per inch.

What is QPaintDevice?

The QPaintDevice class is the base class of objects that can be painted on with QPainter.


1 Answers

I assume physical is the actual resolution of the device and logical is what the user has set in the os preferences. This is popular with retina or other high resolution displays where using the physical dots for pixels would result in everything being too small.

I found this windows specific information: http://msdn.microsoft.com/en-us/library/windows/apps/ff684173

Because actual pixel sizes vary, text that is readable on one monitor might be too small on another monitor. Also, people have different preferences—some people prefer larger text. For this reason, Windows enables the user to change the DPI setting. For example, if the user sets the display to 144 DPI, a 72-point font is 144 pixels tall. The standard DPI settings are 100% (96 DPI), 125% (120 DPI), and 150% (144 DPI). The user can also apply a custom setting. Starting in Windows 7, DPI is a per-user setting.

Even better: QT docs:

A note on logical vs physical dots per inch: physical DPI is based on the actual physical pixel sizes when available, and is useful for print preview and other cases where it's desirable to know the exact physical dimensions of screen displayed contents. Logical dots per inch are used to convert font and user interface elements from point sizes to pixel sizes, and might be different from the physical dots per inch. The logical dots per inch are sometimes user-settable in the desktop environment's settings panel, to let the user globally control UI and font sizes in different applications.

like image 195
Sarien Avatar answered Sep 29 '22 11:09

Sarien