PDA

View Full Version : Setting QTabWidget's Text with a QStyle



taurho
11th March 2009, 13:23
Hi,

I am trying to change the QTabWidget's text to a different color using a Style. Right now I have a subclass of QWindowsStyle



class MyWindowsStyle : public QWindowsStyle
{
void drawComplexControl
(
ComplexControl control,
const QStyleOptionComplex * option,
QPainter * painter,
const QWidget * widget = 0
) const
{
switch(control)
{
case CC_GroupBox:
if( widget != 0 )
{
QStyleOptionGroupBox *groupBox = new QStyleOptionGroupBox(*(qstyleoption_cast<const QStyleOptionGroupBox*>(option)) );
groupBox->textColor = QColor(255, 255, 255);

QWindowsStyle::drawComplexControl( control, groupBox, painter, widget );
}
else
{
QWindowsStyle::drawComplexControl( control, option, painter, widget );
}
break; // end case CC_GroupBox
default:
QWindowsStyle::drawComplexControl( control, option, painter, widget );
}
}
};


that changes the text of QGroupBox'es to a different color. I wanted to extend this class to change the color of the TabWidget's text.
I can not figure out, how to this for a QTabWidget ... Any ideas?

(I know I can just use the QTabWidget::setTabTextColor, but than I would have to do this every time I use the TabWidget and it would not work good together with other styles)

Taurho