Fix QWidget::metric to use widget screen dpr instead of app-dpr
Use the widget screen dpr in calculations rather than qApp->devicePixelRatio(). The screen may have been directly set (without the window handle being initialized) Task-number: QTBUG-103309 Task-number: QTBUG-49663 Task-number: QTBUG-101947 Task-number: QTBUG-102982 Change-Id: I2af2073640b171baf68575e3bc93b29b6a9a471d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
8e15aeee76
commit
344e4cb9be
@ -12690,15 +12690,7 @@ void QWidget::activateWindow()
|
||||
*/
|
||||
int QWidget::metric(PaintDeviceMetric m) const
|
||||
{
|
||||
QWindow *topLevelWindow = nullptr;
|
||||
QScreen *screen = nullptr;
|
||||
if (QWidget *topLevel = window()) {
|
||||
topLevelWindow = topLevel->windowHandle();
|
||||
if (topLevelWindow)
|
||||
screen = topLevelWindow->screen();
|
||||
}
|
||||
if (!screen && QGuiApplication::primaryScreen())
|
||||
screen = QGuiApplication::primaryScreen();
|
||||
QScreen *screen = this->screen();
|
||||
|
||||
if (!screen) {
|
||||
if (m == PdmDpiX || m == PdmDpiY)
|
||||
@ -12733,12 +12725,11 @@ int QWidget::metric(PaintDeviceMetric m) const
|
||||
} else if (m == PdmPhysicalDpiY) {
|
||||
return qRound(screen->physicalDotsPerInchY());
|
||||
} else if (m == PdmDevicePixelRatio) {
|
||||
return topLevelWindow ? topLevelWindow->devicePixelRatio() : qApp->devicePixelRatio();
|
||||
return screen->devicePixelRatio();
|
||||
} else if (m == PdmDevicePixelRatioScaled) {
|
||||
return (QPaintDevice::devicePixelRatioFScale() *
|
||||
(topLevelWindow ? topLevelWindow->devicePixelRatio() : qApp->devicePixelRatio()));
|
||||
return QPaintDevice::devicePixelRatioFScale() * screen->devicePixelRatio();
|
||||
} else {
|
||||
val = QPaintDevice::metric(m);// XXX
|
||||
val = QPaintDevice::metric(m);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user