Windows style: use correct value for title bar height

The title bar height = caption bar height + resize border thickness.

This calculation is used by many open source repositories for quite
a long time, including Microsoft's own famous products such as
Windows Terminal. And if you use AdjustWindowRectEx() to get the
title bar height, the result is also exactly the same, so this should
be the correct calculation.

Normally, when DPI is 96, it should be 23 + (4 + 4) = 31px.

Pick-to: 6.6
Change-Id: I0a2de3b55d5b62327eacc7e2ff5dc23771b8efdb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Yuhang Zhao 2022-10-25 13:44:43 +08:00 committed by Yuhang Zhao
parent 95332cc376
commit 47ee4eae6a
2 changed files with 9 additions and 11 deletions

View File

@ -259,11 +259,8 @@ int QWindowsVistaStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, c
: QWindowsThemeData::themeSize(widget, nullptr, QWindowsVistaStylePrivate::ProgressTheme, PP_CHUNKVERT).height();
case QStyle::PM_SliderThickness:
return QWindowsThemeData::themeSize(widget, nullptr, QWindowsVistaStylePrivate::TrackBarTheme, TKP_THUMB).height();
case QStyle::PM_TitleBarHeight: {
return widget && (widget->windowType() == Qt::Tool)
? GetSystemMetrics(SM_CYSMCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME)
: GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME);
}
case QStyle::PM_TitleBarHeight:
return QWindowsStylePrivate::pixelMetricFromSystemDp(QStyle::PM_TitleBarHeight, option, widget);
case QStyle::PM_MdiSubWindowFrameWidth:
return QWindowsThemeData::themeSize(widget, nullptr, QWindowsVistaStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width();
case QStyle::PM_DockWidgetFrameWidth:

View File

@ -265,12 +265,13 @@ int QWindowsStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, const
case QStyle::PM_DockWidgetFrameWidth:
return GetSystemMetrics(SM_CXFRAME);
case QStyle::PM_TitleBarHeight:
if (widget && (widget->windowType() == Qt::Tool)) {
// MS always use one less than they say
return GetSystemMetrics(SM_CYSMCAPTION) - 1;
}
return GetSystemMetrics(SM_CYCAPTION) - 1;
case QStyle::PM_TitleBarHeight: {
const int resizeBorderThickness =
GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
if (widget && (widget->windowType() == Qt::Tool))
return GetSystemMetrics(SM_CYSMCAPTION) + resizeBorderThickness;
return GetSystemMetrics(SM_CYCAPTION) + resizeBorderThickness;
}
case QStyle::PM_ScrollBarExtent:
{