Unsolved How to relate Logical DPI, Physical DPI, PPI and Device Pixel Ratio
-
I am trying to understand the relationship between Logical Dots Per Inch, Physical Dots Per Inch, Pixel Per Inch and Device Pixel Ratio. To test these values I created a button in my main window which outputs my screen data.
Note 1: I have 2 screens, I am only showing the output of my second screen at different scaling factors.
Note 2: I have changed per inch to per cm for consistency sincephysicalSize()
outputs in millimetres andlogicalDPI()
andphysicalDPI()
outputs in inches.void MainWindow::on_pushButton_clicked() { QList<QScreen*> screens = qApp->screens(); for(int ii = 0; ii < screens.length(); ++ii) { QSize pixelSize = screens[ii]->size(); QSizeF physicalSize = screens[ii]->physicalSize(); double devicePixelRatio = screens[ii]->devicePixelRatio(); double logicalDPIX = screens[ii]->logicalDotsPerInchX(); double logicalDPIY = screens[ii]->logicalDotsPerInchY(); double logicalDPI = screens[ii]->logicalDotsPerInch(); double physicalDPIX = screens[ii]->physicalDotsPerInchX(); double physicalDPIY = screens[ii]->physicalDotsPerInchY(); double physicalDPI = screens[ii]->physicalDotsPerInch(); double pixelValX = pixelSize.width(); double pixelValY = pixelSize.height(); double physicalSizeX_cm = physicalSize.width() / 10.0; double physicalSizeY_cm = physicalSize.height() / 10.0; double calcPixelPerCMX = pixelValX / physicalSizeX_cm; double calcPixelPerCMY = pixelValY / physicalSizeY_cm; double givenLogicalDotsPerCMX = logicalDPIX * 2.54; double givenLogicalDotsPerCMY = logicalDPIY * 2.54; double givenLogicalDotsPerCM = logicalDPI * 2.54; double givenPhysicalDotsPerCMX = physicalDPIX * 2.54; double givenPhysicalDotsPerCMY = physicalDPIY * 2.54; double givenPhysicalDotsPerCM = physicalDPI * 2.54; double ratioLogicalDPCMvsPPCMX = givenLogicalDotsPerCMX / calcPixelPerCMX; double ratioLogicalDPCMvsPPCMY = givenLogicalDotsPerCMY / calcPixelPerCMY; double ratioPhysicalDPCMvsPPCMX = givenPhysicalDotsPerCMX / calcPixelPerCMX; double ratioPhysicalDPCMvsPPCMY = givenPhysicalDotsPerCMY / calcPixelPerCMY; qDebug() << "\n\nScreen: " << ii; qDebug() << "Device Pixel Ratio: " << devicePixelRatio; qDebug() << "Pixel in X-Direction: " << pixelValX; qDebug() << "Pixel in Y-Direction: " << pixelValY; qDebug() << "Physical Size X-Direction in CM: " << physicalSizeX_cm; qDebug() << "Physical Size Y-Direction in CM: " << physicalSizeY_cm; qDebug() << "Calculated Pixel Per CM in X-Direction: " << calcPixelPerCMX; qDebug() << "Calculated Pixel Per CM in Y-Direction: " << calcPixelPerCMY; qDebug() << "Qt Logical Dots Per CM in X-Direction: " << givenLogicalDotsPerCMX; qDebug() << "Qt Logical Dots Per CM in Y-Direction: " << givenLogicalDotsPerCMY; qDebug() << "Qt Logical Dots Per CM Average: " << givenLogicalDotsPerCM; qDebug() << "Qt Physical Dots Per CM in X-Direction: " << givenPhysicalDotsPerCMX; qDebug() << "Qt Physical Dots Per CM in Y-Direction: " << givenPhysicalDotsPerCMY; qDebug() << "Qt Physical Dots Per CM Average: " << givenPhysicalDotsPerCM; qDebug() << "Ratio of Logical Dots Per CM vs Pixel Per CM in X-Direction: " << ratioLogicalDPCMvsPPCMX; qDebug() << "Ratio of Logical Dots Per CM vs Pixel Per CM in Y-Direction: " << ratioLogicalDPCMvsPPCMY; qDebug() << "Ratio of Physical Dots Per CM vs Pixel Per CM in X-Direction: " << ratioPhysicalDPCMvsPPCMX; qDebug() << "Ratio of Physical Dots Per CM vs Pixel Per CM in Y-Direction: " << ratioPhysicalDPCMvsPPCMY; } }
Output at 100% Scaling:
Device Pixel Ratio: 1 Pixel in X-Direction: 1920 Pixel in Y-Direction: 1080 Physical Size X-Direction in CM: 34.4 Physical Size Y-Direction in CM: 19.3 Calculated Pixel Per CM in X-Direction: 55.814 Calculated Pixel Per CM in Y-Direction: 55.9585 Qt Logical Dots Per CM in X-Direction: 243.84 Qt Logical Dots Per CM in Y-Direction: 243.84 Qt Logical Dots Per CM Average: 243.84 Qt Physical Dots Per CM in X-Direction: 360.089 Qt Physical Dots Per CM in Y-Direction: 361.022 Qt Physical Dots Per CM Average: 360.556 Ratio of Logical Dots Per CM vs Pixel Per CM in X-Direction: 4.3688 Ratio of Logical Dots Per CM vs Pixel Per CM in Y-Direction: 4.35751 Ratio of Physical Dots Per CM vs Pixel Per CM in X-Direction: 6.4516 Ratio of Physical Dots Per CM vs Pixel Per CM in Y-Direction: 6.4516
Output at 125% Scaling:
Device Pixel Ratio: 1 Pixel in X-Direction: 1920 Pixel in Y-Direction: 1080 Physical Size X-Direction in CM: 34.4 Physical Size Y-Direction in CM: 19.3 Calculated Pixel Per CM in X-Direction: 55.814 Calculated Pixel Per CM in Y-Direction: 55.9585 Qt Logical Dots Per CM in X-Direction: 304.8 Qt Logical Dots Per CM in Y-Direction: 304.8 Qt Logical Dots Per CM Average: 304.8 Qt Physical Dots Per CM in X-Direction: 360.089 Qt Physical Dots Per CM in Y-Direction: 361.022 Qt Physical Dots Per CM Average: 360.556 Ratio of Logical Dots Per CM vs Pixel Per CM in X-Direction: 5.461 Ratio of Logical Dots Per CM vs Pixel Per CM in Y-Direction: 5.44689 Ratio of Physical Dots Per CM vs Pixel Per CM in X-Direction: 6.4516 Ratio of Physical Dots Per CM vs Pixel Per CM in Y-Direction: 6.4516
Output at 150% Scaling:
Device Pixel Ratio: 1 Pixel in X-Direction: 1920 Pixel in Y-Direction: 1080 Physical Size X-Direction in CM: 34.4 Physical Size Y-Direction in CM: 19.3 Calculated Pixel Per CM in X-Direction: 55.814 Calculated Pixel Per CM in Y-Direction: 55.9585 Qt Logical Dots Per CM in X-Direction: 365.76 Qt Logical Dots Per CM in Y-Direction: 365.76 Qt Logical Dots Per CM Average: 365.76 Qt Physical Dots Per CM in X-Direction: 360.089 Qt Physical Dots Per CM in Y-Direction: 361.022 Qt Physical Dots Per CM Average: 360.556 Ratio of Logical Dots Per CM vs Pixel Per CM in X-Direction: 6.5532 Ratio of Logical Dots Per CM vs Pixel Per CM in Y-Direction: 6.53627 Ratio of Physical Dots Per CM vs Pixel Per CM in X-Direction: 6.4516 Ratio of Physical Dots Per CM vs Pixel Per CM in Y-Direction: 6.4516
The only thing that changes because of scaling is
logicalDotsPerInch
I would assumedevicePixelRatio
to change as well with scaling but that is not the case, why?How can I interpret the current scaling factor for the screen given only
logicalDotsPerInch
is changing? Can I assume that all screens at 100% scaling will have 96logicalDotsPerInch
(i.e. 243.84 logical dots per cm) and then calculate the scaling using this value? -
Hi, there was a similar question a few month ago
https://forum.qt.io/topic/125521/how-to-understand-logical-dpi-and-physical-dpi-in-qscreen
Maybe it help you to understand better.@CJha said in How to relate Logical DPI, Physical DPI, PPI and Device Pixel Ratio:
I would assume devicePixelRatio to change as well with scaling but that is not the case, why?
If I'm not mistaken the
DPR
(device pixel ratio) IS the scaling factor.Qt uses a model where the application coordinate system is independent of the display device resolution. The application operates in device-independent pixels, which are then mapped to the physical pixels of the display via a scale factor, known as the device pixel ratio. The scale factor is expressed as a floating point number, for example 1.0 or 2.0, or informally as 1x and 2x. For example, creating a QWindow or QWidget, and setting its size to 200x200 will result in a corresponding window of 200x200 pixels on a normal density display (with a device pixel ratio of 1.0),
but will result in a window of 400x400 pixel on a high density display (with a device pixel ratio of 2.0).
-
@Pl45m4 Thanks! I didn't see the previous question. The device pixel ratio is not giving me any scaling factor, that's my basic question. At all the different scaling factors my device pixel ratio remains at 1, as I have shown above. I would assume the device pixel ratio to be 1.25 at 125% scaling, 1.5 at 150% scaling and so on, but that's not the case.
-
@CJha said in How to relate Logical DPI, Physical DPI, PPI and Device Pixel Ratio:
I would assume the device pixel ratio to be 1.25 at 125% scaling, 1.5 at 150% scaling and so on, but that's not the case.
How do you "scale" your screens? Do you actually or are those numers just calculations?
-
@Pl45m4 I go to the settings of Windows and apply a scaling under "Scale and layout" for my screen