QMacStyle - fix a weird NSBox geometry

For some reason, displayRectIgnoringOpacity renders NSBox with a
smaller height than we asked. So let's ask for more and translate.

Change-Id: I6e03ad99d1ccf746c89d58dd37d53d0087f15282
Fixes: QTBUG-71741
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Timur Pocheptsov 2019-01-25 12:10:34 +01:00
parent d8d2025f06
commit 8915904e2a
1 changed files with 16 additions and 1 deletions

View File

@ -2996,7 +2996,20 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
// inContext:, but only in light mode. In dark mode, we use a custom NSBox subclass,
// QDarkNSBox, of type NSBoxCustom. Its appearance is close enough to the real thing so
// we can use this for now.
d->drawNSViewInRect(box, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) {
auto adjustedRect = opt->rect;
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);
needTranslation = true;
}
d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx, const CGRect &rect) {
if (QTabWidget *tabWidget = qobject_cast<QTabWidget *>(opt->styleObject))
clipTabBarFrame(opt, this, ctx);
CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height);
@ -3005,6 +3018,8 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
|| [box isMemberOfClass:QDarkNSBox.class]) {
[box drawRect:rect];
} else {
if (needTranslation)
CGContextTranslateCTM(ctx, 0.0, 4.0);
[box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext];
}
});