QMdiArea: on macOS using tabs, render document icons next to the text
This is closer to what titles of documents look like in macOS apps, even though MDI is not a well-defined concept on this platform. To implement this, the QCommonStylePrivate::tabLayout method had to be made virtual, as it is called by the QCommonStyle class. It was already reimplemented in QMacStylePrivate, but didn't get called in all cases. Now that it is called as an override, adjust the icon placement to include the padding so that we get identical results to 5.13 for normal tab widgets. Change-Id: I7a63f6d76891146ca713259096a7737a86584d81 Fixes: QTBUG-63445 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
b6632443d4
commit
2ed59f0d42
@ -1388,14 +1388,22 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg
|
||||
// High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize
|
||||
tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height()));
|
||||
|
||||
*iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2,
|
||||
tabIconSize.width(), tabIconSize.height());
|
||||
const int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2 - hpadding;
|
||||
|
||||
if (opt->documentMode) {
|
||||
// documents show the icon as part of the the text
|
||||
const int textWidth =
|
||||
opt->fontMetrics.boundingRect(tr, Qt::AlignCenter | Qt::TextShowMnemonic, opt->text).width();
|
||||
*iconRect = QRect(tr.center().x() - textWidth / 2 - stylePadding - tabIconSize.width(),
|
||||
tr.center().y() - tabIconSize.height() / 2,
|
||||
tabIconSize.width(), tabIconSize.height());
|
||||
} else {
|
||||
*iconRect = QRect(tr.left() + stylePadding, tr.center().y() - tabIconSize.height() / 2,
|
||||
tabIconSize.width(), tabIconSize.height());
|
||||
}
|
||||
if (!verticalTabs)
|
||||
*iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
|
||||
|
||||
int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
|
||||
stylePadding -= hpadding;
|
||||
|
||||
tr.setLeft(tr.left() + stylePadding + tabIconSize.width() + 4);
|
||||
tr.setRight(tr.right() - stylePadding - tabIconSize.width() - 4);
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ public:
|
||||
CocoaControlType windowButtonCocoaControl(QStyle::SubControl sc) const;
|
||||
|
||||
#if QT_CONFIG(tabbar)
|
||||
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const;
|
||||
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const override;
|
||||
static Direction tabDirection(QTabBar::Shape shape);
|
||||
static bool verticalTabs(QMacStylePrivate::Direction tabDirection);
|
||||
#endif
|
||||
|
@ -122,7 +122,7 @@ public:
|
||||
|
||||
mutable QIcon tabBarcloseButtonIcon;
|
||||
#if QT_CONFIG(tabbar)
|
||||
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;
|
||||
virtual void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;
|
||||
#endif
|
||||
|
||||
int animationFps;
|
||||
|
Loading…
x
Reference in New Issue
Block a user