diff options
author | Andre de la Rocha <andre.rocha@qt.io> | 2018-04-11 13:13:58 +0200 |
---|---|---|
committer | Andre de la Rocha <andre.rocha@qt.io> | 2018-08-30 00:21:38 +0000 |
commit | 5f2ab16bbc6e6345f3ec2229b712ef309f1ff18b (patch) | |
tree | cc022514c3e467a0391fbbdc050e686367326c18 /src/widgets | |
parent | 1bf0344b9f41516ef28cd6c047aab801e24ac8df (diff) |
Windows: Fix MDI child window titles in High-DPI displays
This change improves the appearance of MDI child windows in a High-DPI
display for applications using the WindowsVista style, with the
Qt::AA_EnableHighDpiScaling attribute set.
Task-number: QTBUG-64708
Change-Id: I5e9fbd23809b440ffd33e4948c83d115cc6e1910
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
(cherry picked from commit 0b9a301e89c6473091a9b80552d6e4058d35bbe6)
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 28 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsxpstyle.cpp | 16 |
2 files changed, 24 insertions, 20 deletions
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 906c3ed7c3..88eb0c6e79 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -2159,12 +2159,12 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) { if (!buttonVisible(subControl, tb)) return rect; + const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget); const bool isToolTitle = false; const int height = tb->rect.height(); const int width = tb->rect.width(); const int buttonWidth = - qRound(qreal(GetSystemMetrics(SM_CXSIZE)) * QWindowsStylePrivate::nativeMetricScaleFactor(widget) - - QStyleHelper::dpiScaled(4)); + qRound(qreal(GetSystemMetrics(SM_CXSIZE)) * factor - QStyleHelper::dpiScaled(4)); const int frameWidth = proxy()->pixelMetric(PM_MdiSubWindowFrameWidth, option, widget); const bool sysmenuHint = (tb->titleBarFlags & Qt::WindowSystemMenuHint) != 0; @@ -2178,31 +2178,31 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt rect = QRect(frameWidth, 0, width - (buttonWidth + frameWidth + 10), height); if (isToolTitle) { if (sysmenuHint) { - rect.adjust(0, 0, -buttonWidth - 3, 0); + rect.adjust(0, 0, int(-buttonWidth - 3 * factor), 0); } if (minimizeHint || maximizeHint) - rect.adjust(0, 0, -buttonWidth - 2, 0); + rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0); } else { if (sysmenuHint) { - const int leftOffset = height - 8; - rect.adjust(leftOffset, 0, 0, 4); + const int leftOffset = int(height - 8 * factor); + rect.adjust(leftOffset, 0, 0, int(4 * factor)); } if (minimizeHint) - rect.adjust(0, 0, -buttonWidth - 2, 0); + rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0); if (maximizeHint) - rect.adjust(0, 0, -buttonWidth - 2, 0); + rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0); if (contextHint) - rect.adjust(0, 0, -buttonWidth - 2, 0); + rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0); if (shadeHint) - rect.adjust(0, 0, -buttonWidth - 2, 0); + rect.adjust(0, 0, int(-buttonWidth - 2 * factor), 0); } - rect.translate(0, 2); + rect.translate(0, int(2 * factor)); rect = visualRect(option->direction, option->rect, rect); break; case SC_TitleBarSysMenu: { - const int controlTop = 6; - const int controlHeight = height - controlTop - 3; + const int controlTop = int(6 * factor); + const int controlHeight = int(height - controlTop - 3 * factor); int iconExtent = proxy()->pixelMetric(PM_SmallIconSize); QSize iconSize = tb->icon.actualSize(QSize(iconExtent, iconExtent)); if (tb->icon.isNull()) @@ -2210,7 +2210,7 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt int hPad = (controlHeight - iconSize.height())/2; int vPad = (controlHeight - iconSize.width())/2; rect = QRect(frameWidth + hPad, controlTop + vPad, iconSize.width(), iconSize.height()); - rect.translate(0, 3); + rect.translate(0, int(3 * factor)); rect = visualRect(option->direction, option->rect, rect); } break; diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 8656ca6c09..603bceff68 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -522,7 +522,8 @@ bool QWindowsXPStylePrivate::isTransparent(XPThemeData &themeData) QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) { HRGN hRgn = 0; - RECT rect = themeData.toRECT(themeData.rect); + const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(themeData.widget); + RECT rect = themeData.toRECT(QRect(themeData.rect.topLeft() / factor, themeData.rect.size() / factor)); if (!SUCCEEDED(GetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId, themeData.stateId, &rect, &hRgn))) { return QRegion(); @@ -551,7 +552,7 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) RECT *r = reinterpret_cast<RECT*>(rd->Buffer); for (uint i = 0; i < rd->rdh.nCount; ++i) { QRect rect; - rect.setCoords(r->left, r->top, r->right - 1, r->bottom - 1); + rect.setCoords(int(r->left * factor), int(r->top * factor), int((r->right - 1) * factor), int((r->bottom - 1) * factor)); ++r; region |= rect; } @@ -1786,9 +1787,9 @@ case PE_Frame: else stateId = FS_INACTIVE; - int fwidth = frm->lineWidth + frm->midLineWidth; + int fwidth = int((frm->lineWidth + frm->midLineWidth) / QWindowsStylePrivate::nativeMetricScaleFactor(widget)); - XPThemeData theme(0, p, themeNumber, 0, stateId); + XPThemeData theme(widget, p, themeNumber, 0, stateId); if (!theme.isValid()) break; @@ -2979,6 +2980,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo { if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) { + const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget); bool isActive = tb->titleBarState & QStyle::State_Active; XPThemeData theme(widget, p, QWindowsXPStylePrivate::WindowTheme); if (sub & SC_TitleBarLabel) { @@ -3005,13 +3007,15 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef); QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef)); p->setPen(textShadow); - p->drawText(ir.x() + 3, ir.y() + 2, ir.width() - 1, ir.height(), + p->drawText(int(ir.x() + 3 * factor), int(ir.y() + 2 * factor), + int(ir.width() - 1 * factor), ir.height(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text); } COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT); QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText)); p->setPen(textColor); - p->drawText(ir.x() + 2, ir.y() + 1, ir.width() - 2, ir.height(), + p->drawText(int(ir.x() + 2 * factor), int(ir.y() + 1 * factor), + int(ir.width() - 2 * factor), ir.height(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text); } if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) { |