Fallback to PerMonitorDpiAware if V2DpiAware is not supported by system
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 might not be supported on some legacy Windows 10 editions (prior Creator Update). In this case SetProcessDpiAwarenessContext returns ERROR_INVALID_PARAMETER. Fallback to DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE using old API SetProcessDpiAwareness in such cases as the most suitable. Fixes: QTBUG-103733 Change-Id: I39216e63ecfcae96aaa159237a52b0a76bc5d956 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> (cherry picked from commit 4a2c31103c7c993c87f88087811e02804adfabf3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
86e8860ea0
commit
9e6f83307d
@ -382,21 +382,19 @@ void QWindowsContext::setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWindowsContext::setProcessDpiV2Awareness()
|
bool QWindowsContext::setProcessDpiV2Awareness()
|
||||||
{
|
{
|
||||||
qCDebug(lcQpaWindows) << __FUNCTION__;
|
qCDebug(lcQpaWindows) << __FUNCTION__;
|
||||||
const BOOL ok = SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
const BOOL ok = SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||||
if (ok) {
|
if (!ok) {
|
||||||
QWindowsContextPrivate::m_v2DpiAware = true;
|
|
||||||
} else {
|
|
||||||
const HRESULT errorCode = GetLastError();
|
const HRESULT errorCode = GetLastError();
|
||||||
// ERROR_ACCESS_DENIED means set externally (MSVC manifest or external app loading Qt plugin).
|
qCWarning(lcQpaWindows).noquote().nospace() << "setProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) failed: "
|
||||||
// Silence warning in that case unless debug is enabled.
|
|
||||||
if (errorCode != ERROR_ACCESS_DENIED || lcQpaWindows().isDebugEnabled()) {
|
|
||||||
qWarning().noquote().nospace() << "setProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) failed: "
|
|
||||||
<< QWindowsContext::comErrorString(errorCode);
|
<< QWindowsContext::comErrorString(errorCode);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
QWindowsContextPrivate::m_v2DpiAware = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QWindowsContext::isDarkMode()
|
bool QWindowsContext::isDarkMode()
|
||||||
|
@ -121,7 +121,7 @@ public:
|
|||||||
static void setTabletAbsoluteRange(int a);
|
static void setTabletAbsoluteRange(int a);
|
||||||
void setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness);
|
void setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness);
|
||||||
static int processDpiAwareness();
|
static int processDpiAwareness();
|
||||||
void setProcessDpiV2Awareness();
|
bool setProcessDpiV2Awareness();
|
||||||
|
|
||||||
static bool isDarkMode();
|
static bool isDarkMode();
|
||||||
|
|
||||||
|
@ -223,16 +223,20 @@ void QWindowsIntegrationPrivate::parseOptions(QWindowsIntegration *q, const QStr
|
|||||||
|
|
||||||
if (!dpiAwarenessSet) { // Set only once in case of repeated instantiations of QGuiApplication.
|
if (!dpiAwarenessSet) { // Set only once in case of repeated instantiations of QGuiApplication.
|
||||||
if (!QCoreApplication::testAttribute(Qt::AA_PluginApplication)) {
|
if (!QCoreApplication::testAttribute(Qt::AA_PluginApplication)) {
|
||||||
|
|
||||||
// DpiAwareV2 requires using new API
|
|
||||||
if (dpiAwareness == QtWindows::ProcessPerMonitorV2DpiAware) {
|
if (dpiAwareness == QtWindows::ProcessPerMonitorV2DpiAware) {
|
||||||
m_context.setProcessDpiV2Awareness();
|
// DpiAwareV2 requires using new API
|
||||||
qCDebug(lcQpaWindows)
|
if (m_context.setProcessDpiV2Awareness()) {
|
||||||
<< __FUNCTION__ << "DpiAwareness: DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2";
|
qCDebug(lcQpaWindows, "DpiAwareness: DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2");
|
||||||
|
dpiAwarenessSet = true;
|
||||||
} else {
|
} else {
|
||||||
|
// fallback to old API
|
||||||
|
dpiAwareness = QtWindows::ProcessPerMonitorDpiAware;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dpiAwarenessSet) {
|
||||||
m_context.setProcessDpiAwareness(dpiAwareness);
|
m_context.setProcessDpiAwareness(dpiAwareness);
|
||||||
qCDebug(lcQpaWindows)
|
qCDebug(lcQpaWindows) << "DpiAwareness=" << dpiAwareness
|
||||||
<< __FUNCTION__ << "DpiAwareness=" << dpiAwareness
|
|
||||||
<< "effective process DPI awareness=" << QWindowsContext::processDpiAwareness();
|
<< "effective process DPI awareness=" << QWindowsContext::processDpiAwareness();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user