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
32 QTabBar *tabBar { qobject_cast<QTabBar *>( parent() ) };
36 if ( element == CE_TabBarTab && mTabStyles.contains( tabBar->tabAt( option->rect.center() ) ) )
38 if (
const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>( option ) )
42 if ( style.overrideFont )
44 painter->setFont( style.font );
46 QStyleOptionTab opt { *tab };
47 if ( style.overrideColor && style.color.isValid( ) )
49 opt.palette.setBrush( QPalette::WindowText, style.color );
51 QProxyStyle::drawControl( element, &opt, painter, widget );
58 QProxyStyle::drawControl( element, option, painter, widget );
64 mTabStyles.insert( tabIndex, style );
67const QMap<int, QgsAttributeEditorElement::LabelStyle> &QgsTabBarProxyStyle::tabStyles()
const
73QgsTabBar::QgsTabBar( QWidget *parent )
78void QgsTabBar::setTabBarStyle( QgsTabBarProxyStyle *tabStyle )
80 mTabBarStyle = tabStyle;
83QSize QgsTabBar::tabSizeHint(
int index )
const
85 if ( mTabBarStyle->tabStyles().contains( index ) )
90 const QSize s = QTabBar::tabSizeHint( index );
91 const QFontMetrics fm( font() );
92 const int w = fm.horizontalAdvance( tabText( index ) );
93 const QFont f = tabStyle.
font;
94 const QFontMetrics bfm( f );
95 const int bw = bfm.horizontalAdvance( tabText( index ) );
96 return QSize( s.width() - w + bw, s.height() );
100 return QTabBar::tabSizeHint( index );
105 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.