diff options
Diffstat (limited to 'src/plugins/styles/mac/qmacstyle_mac.mm')
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac.mm | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 24efb641f2..e2599e8c6b 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -3096,13 +3096,18 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai bool needTranslation = false; if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave && !qt_mac_applicationIsInDarkMode()) { - // Another surprise from AppKit (SDK 10.14) - -displayRectIgnoringOpacity: - // is different from drawRect: for some Apple-known reason box is smaller - // in height than we need, resulting in tab buttons sitting too high/not - // centered. Attempts to play with insets etc did not work - the same wrong - // height. Simple translation is not working (too much space "at bottom"), - // so we make it bigger and translate (otherwise it's clipped at bottom btw). - adjustedRect.adjust(0, 0, 0, 3); + // In Aqua theme we have to use the 'default' NSBox (as opposite + // to the 'custom' QDarkNSBox we use in dark theme). Since -drawRect: + // does nothing in default NSBox, we call -displayRectIgnoringOpaticty:. + // Unfortunately, the resulting box is smaller then the actual rect we + // wanted. This can be seen, e.g. because tabs (buttons) are misaligned + // vertically and even worse, if QTabWidget has autoFillBackground + // set, this background overpaints NSBox making it to disappear. + // We trick our NSBox to render in a larger rectangle, so that + // the actuall result (which is again smaller than requested), + // more or less is what we really want. We'll have to adjust CTM + // and translate accordingly. + adjustedRect.adjust(0, 0, 6, 6); needTranslation = true; } d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx, const CGRect &rect) { @@ -3117,7 +3122,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai [box drawRect:rect]; } else { if (needTranslation) - CGContextTranslateCTM(ctx, 0.0, 4.0); + CGContextTranslateCTM(ctx, -3.0, 5.0); [box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext]; } }); @@ -4613,6 +4618,7 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, case SE_ToolBoxTabContents: rect = QCommonStyle::subElementRect(sr, opt, widget); break; + case SE_PushButtonBevel: case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { // Comment from the old HITheme days: @@ -4626,9 +4632,20 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, const auto ct = cocoaControlType(btn, widget); const auto cs = d->effectiveAquaSizeConstrain(btn, widget); const auto cw = QMacStylePrivate::CocoaControl(ct, cs); - const auto frameRect = cw.adjustedControlFrame(btn->rect); - const auto titleMargins = cw.titleMargins(); - rect = (frameRect - titleMargins).toRect(); + auto frameRect = cw.adjustedControlFrame(btn->rect); + if (sr == SE_PushButtonContents) { + frameRect -= cw.titleMargins(); + } else { + auto *pb = static_cast<NSButton *>(d->cocoaControl(cw)); + if (cw.type != QMacStylePrivate::Button_SquareButton) { + frameRect = QRectF::fromCGRect([pb alignmentRectForFrame:pb.frame]); + if (cw.type == QMacStylePrivate::Button_PushButton) + frameRect -= pushButtonShadowMargins[cw.size]; + else if (cw.type == QMacStylePrivate::Button_PullDown) + frameRect -= pullDownButtonShadowMargins[cw.size]; + } + } + rect = frameRect.toRect(); } break; case SE_HeaderLabel: { |