16#include "moc_qgstabbarproxystyle.cpp"
18#include <QStyleOption>
24QgsTabBarProxyStyle::QgsTabBarProxyStyle( QTabBar *tabBar )
29void QgsTabBarProxyStyle::drawControl( ControlElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget )
const
31 QTabBar *tabBar { qobject_cast<QTabBar *>( parent() ) };
35 if ( element == CE_TabBarTab && mTabStyles.contains( tabBar->tabAt( option->rect.center() ) ) )
37 if (
const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>( option ) )
41 if ( style.overrideFont )
43 painter->setFont( style.font );
45 QStyleOptionTab opt { *tab };
46 if ( style.overrideColor && style.color.isValid() )
48 opt.palette.setBrush( QPalette::WindowText, style.color );
50 QProxyStyle::drawControl( element, &opt, painter, widget );
57 QProxyStyle::drawControl( element, option, painter, widget );
62 mTabStyles.insert( tabIndex, style );
65const QMap<int, QgsAttributeEditorElement::LabelStyle> &QgsTabBarProxyStyle::tabStyles()
const
71QgsTabBar::QgsTabBar( QWidget *parent )
76void QgsTabBar::setTabBarStyle( QgsTabBarProxyStyle *tabStyle )
78 mTabBarStyle = tabStyle;
81QSize QgsTabBar::tabSizeHint(
int index )
const
83 if ( mTabBarStyle->tabStyles().contains( index ) )
88 const QSize s = QTabBar::tabSizeHint( index );
89 const QFontMetrics fm( font() );
90 const int w = fm.horizontalAdvance( tabText( index ) );
91 const QFont f = tabStyle.
font;
92 const QFontMetrics bfm( f );
93 const int bw = bfm.horizontalAdvance( tabText( index ) );
94 return QSize( s.width() - w + bw, s.height() );
98 return QTabBar::tabSizeHint( index );
103 return QTabBar::tabSizeHint( index );
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
The TabStyle struct defines color and font overrides for form fields, tabs and groups labels.
bool overrideFont
Override label font.