diff --git a/python/gui/auto_generated/qgstabwidget.sip.in b/python/gui/auto_generated/qgstabwidget.sip.in index 086e5fd1c80..86412a2e8e9 100644 --- a/python/gui/auto_generated/qgstabwidget.sip.in +++ b/python/gui/auto_generated/qgstabwidget.sip.in @@ -80,9 +80,9 @@ Is used to keep track of currently available and visible tabs. .. versionadded:: 3.0 %End - void setTabFont( int tabIndex, const QFont &font ); + void setTabStyle( int tabIndex, const QFont &font, const QColor &color ); %Docstring -Sets the optional custom ``font`` for the tab idenfied by ``tabIndex``. +Sets the optional custom ``font`` and ``color`` for the tab idenfied by ``tabIndex``. .. versionadded:: 3.26 %End diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index 0b9f53296b8..1fce55d112b 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -1611,7 +1611,7 @@ void QgsAttributeForm::init() WidgetInfo widgetInfo = createWidgetFromDef( widgDef, formWidget, mLayer, mContext ); if ( widgetInfo.overrideLabelStyle ) { - widgetInfo.widget->setStyleSheet( QStringLiteral( "QGroupBox::title { color: rgba(%1,%2,%3,%4); }" ).arg( widgetInfo.labelColor.red() ).arg( widgetInfo.labelColor.green() ).arg( widgetInfo.labelColor.blue() ).arg( QString::number( widgetInfo.labelColor.alphaF(), 'f', 4 ) ) ); + widgetInfo.widget->setStyleSheet( QStringLiteral( "QGroupBox::title { color: %1; }" ).arg( widgetInfo.labelColor.name( QColor::HexArgb ) ) ); widgetInfo.widget->setFont( widgetInfo.labelFont ); } layout->addWidget( widgetInfo.widget, row, column, 1, 2 ); @@ -1636,8 +1636,7 @@ void QgsAttributeForm::init() if ( widgDef->overrideLabelStyle() ) { - tabWidget->setTabFont( tabWidget->tabBar()->count() - 1, widgDef->labelFont() ); - tabWidget->tabBar()->setTabTextColor( tabWidget->tabBar()->count() - 1, widgDef->labelColor() ); + tabWidget->setTabStyle( tabWidget->tabBar()->count() - 1, widgDef->labelFont(), widgDef->labelColor() ); } if ( containerDef->visibilityExpression().enabled() ) @@ -2263,7 +2262,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt if ( newWidgetInfo.overrideLabelStyle ) { groupBox->setFont( newWidgetInfo.labelFont ); - groupBox->setStyleSheet( QStringLiteral( "QGroupBox::title { color: rgba(%1,%2,%3,%4); }" ).arg( newWidgetInfo.labelColor.red() ).arg( newWidgetInfo.labelColor.green() ).arg( newWidgetInfo.labelColor.blue() ).arg( QString::number( newWidgetInfo.labelColor.alphaF(), 'f', 4 ) ) ); + groupBox->setStyleSheet( QStringLiteral( "QGroupBox::title { color: %1; }" ).arg( newWidgetInfo.labelColor.name( QColor::HexArgb ) ) ); } } myContainer = groupBox; diff --git a/src/gui/qgstabbarproxystyle.cpp b/src/gui/qgstabbarproxystyle.cpp index 3eb672797a1..be22c75ab67 100644 --- a/src/gui/qgstabbarproxystyle.cpp +++ b/src/gui/qgstabbarproxystyle.cpp @@ -30,16 +30,20 @@ void QgsTabBarProxyStyle::drawControl( ControlElement element, const QStyleOptio { if ( element == CE_TabBarTab && mTabStyles.contains( mTabBar->tabAt( option->rect.center() ) ) ) { - painter->save(); // save the painter to restore later - const TabStyle &style { mTabStyles.value( mTabBar->tabAt( option->rect.center() ) ) }; - painter->setFont( style.font ); // change the defaul font of painter - QProxyStyle::drawControl( element, option, painter, widget ); // paint the TabBarTab using the default drawControl - painter->restore(); // restore to default painter - } - else - { - QProxyStyle::drawControl( element, option, painter, widget ); // use default drawControl to paint all other components without changes. + if ( const QStyleOptionTab *tab = qstyleoption_cast( option ) ) + { + painter->save(); + const TabStyle &style { mTabStyles.value( mTabBar->tabAt( option->rect.center() ) ) }; + painter->setFont( style.font ); + QStyleOptionTab opt { *tab }; + QProxyStyle::drawControl( element, &opt, painter, widget ); + painter->restore(); + return; + } } + + QProxyStyle::drawControl( element, option, painter, widget ); + } void QgsTabBarProxyStyle::addStyle( int tabIndex, const TabStyle &style ) diff --git a/src/gui/qgstabbarproxystyle.h b/src/gui/qgstabbarproxystyle.h index 8ad167c119f..26c22878014 100644 --- a/src/gui/qgstabbarproxystyle.h +++ b/src/gui/qgstabbarproxystyle.h @@ -38,6 +38,7 @@ class QgsTabBarProxyStyle : public QProxyStyle struct TabStyle { QFont font; + QColor color; }; QgsTabBarProxyStyle( QTabBar *tabBar ); diff --git a/src/gui/qgstabwidget.cpp b/src/gui/qgstabwidget.cpp index b45e2fe491d..69470cc5ec9 100644 --- a/src/gui/qgstabwidget.cpp +++ b/src/gui/qgstabwidget.cpp @@ -74,9 +74,9 @@ int QgsTabWidget::realTabIndex( QWidget *widget ) return -1; } -void QgsTabWidget::setTabFont( int tabIndex, const QFont &customFont ) +void QgsTabWidget::setTabStyle( int tabIndex, const QFont &font, const QColor &color ) { - mTabBarStyle->addStyle( tabIndex, QgsTabBarProxyStyle::TabStyle{ customFont } ); + mTabBarStyle->addStyle( tabIndex, QgsTabBarProxyStyle::TabStyle{ font, color } ); } void QgsTabWidget::tabInserted( int index ) diff --git a/src/gui/qgstabwidget.h b/src/gui/qgstabwidget.h index 025c06ab926..81905e1f668 100644 --- a/src/gui/qgstabwidget.h +++ b/src/gui/qgstabwidget.h @@ -92,10 +92,10 @@ class GUI_EXPORT QgsTabWidget : public QTabWidget void tabRemoved( int index ) override; /** - * Sets the optional custom \a font for the tab idenfied by \a tabIndex. + * Sets the optional custom \a font and \a color for the tab idenfied by \a tabIndex. * \since QGIS 3.26 */ - void setTabFont( int tabIndex, const QFont &font ); + void setTabStyle( int tabIndex, const QFont &font, const QColor &color ); private: void synchronizeIndexes();