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.

Change-Id: I0a2de3b55d5b62327eacc7e2ff5dc23771b8efdb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 47ee4eae6ad361e9d3a1df4415562ff092de6644)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Yuhang Zhao 2022-10-25 13:44:43 +08:00 committed by Qt Cherry-pick Bot
parent b5d66b52df
commit 06d434ef28
2 changed files with 9 additions and 11 deletions

View File

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

View File

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