From 06d434ef2829979a8a0587e1c86644ebc92abcfe Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Tue, 25 Oct 2022 13:44:43 +0800 Subject: [PATCH] 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 (cherry picked from commit 47ee4eae6ad361e9d3a1df4415562ff092de6644) Reviewed-by: Qt Cherry-pick Bot --- .../styles/windowsvista/qwindowsvistastyle.cpp | 7 ++----- src/widgets/styles/qwindowsstyle.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index 4f7786c0346..43c310fb445 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -265,11 +265,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: diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index f79136757a0..fd1f8e1c178 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -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: {