QMacStyle - fix PE_InticatorTabClose handling

for the case a custom style sheet is in use and QStyleSheetStyle
replaces the widget (close button) with its parent (QTabBar).
We still need this button though to compare against tabButton
on a hovered tab. This allows us to have, indeed, native-looking
tabs as documented (aka similar to Safari or the "Terminal" application).

Change-Id: I53ff78699e705db6d7c7b84774b8e188a1277535
Fixes: QTBUG-61092
Fixes: QTBUG-74689
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Timur Pocheptsov 2019-03-28 10:42:38 +01:00
parent 6ccbe7ffdf
commit 409e3eab09
2 changed files with 12 additions and 3 deletions

View File

@ -3411,18 +3411,20 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
case PE_IndicatorTabClose: {
// Make close button visible only on the hovered tab.
QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
const QWidget *closeBtn = w;
if (!tabBar) {
// QStyleSheetStyle instead of CloseButton (which has
// a QTabBar as a parent widget) uses the QTabBar itself:
tabBar = qobject_cast<QTabBar *>(const_cast<QWidget*>(w));
closeBtn = decltype(closeBtn)(property("_q_styleSheetRealCloseButton").value<void *>());
}
if (tabBar) {
const bool documentMode = tabBar->documentMode();
const QTabBarPrivate *tabBarPrivate = static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
if (!documentMode ||
(hoveredTabIndex != -1 && ((w == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
(w == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
(hoveredTabIndex != -1 && ((closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
(closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
const bool hover = (opt->state & State_MouseOver);
const bool selected = (opt->state & State_Selected);
const bool pressed = (opt->state & State_Sunken);

View File

@ -4590,8 +4590,12 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
break;
#if QT_CONFIG(tabbar)
case PE_IndicatorTabClose:
if (w)
if (w) {
// QMacStyle needs a real widget, not its parent - to implement
// 'document mode' properly, drawing nothing if a tab is not hovered.
baseStyle()->setProperty("_q_styleSheetRealCloseButton", QVariant::fromValue((void *)w));
w = w->parentWidget(); //match on the QTabBar instead of the CloseButton
}
pseudoElement = PseudoElement_TabBarTabCloseButton;
#endif
@ -4609,6 +4613,9 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
} else {
baseStyle()->drawPrimitive(pe, opt, p, w);
}
if (baseStyle()->property("_q_styleSheetRealCloseButton").toBool())
baseStyle()->setProperty("_q_styleSheetRealCloseButton", QVariant(QVariant::Invalid));
}
QPixmap QStyleSheetStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap& pixmap,