17#include <QStyleOption>
23QgsTabBarProxyStyle::QgsTabBarProxyStyle( QTabBar *tabBar )
28void 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 );
63 mTabStyles.insert( tabIndex, style );
66const QMap<int, QgsAttributeEditorElement::LabelStyle> &QgsTabBarProxyStyle::tabStyles()
const
72QgsTabBar::QgsTabBar( QWidget *parent )
77void QgsTabBar::setTabBarStyle( QgsTabBarProxyStyle *tabStyle )
79 mTabBarStyle = tabStyle;
82QSize QgsTabBar::tabSizeHint(
int index )
const
84 if ( mTabBarStyle->tabStyles().contains( index ) )
86 const QSize s = QTabBar::tabSizeHint( index );
87 const QFontMetrics fm( font() );
88 const int w = fm.horizontalAdvance( tabText( index ) );
89 const QFont f = mTabBarStyle->tabStyles().value( index ).font;
90 const QFontMetrics bfm( f );
91 const int bw = bfm.horizontalAdvance( tabText( index ) );
92 return QSize( s.width() - w + bw, s.height() );
96 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.