Overriding Stylesheet settings
-
Hi,
I have an app that is governed by a stylesheet. Is there a way I can override the color from the stylesheet setting for a specific tab? I already sub-classed QTabBar to use paintEvent. If I select a stylesheet that does not define a background color for the tabs the paintevent works fine, however if I define a background color in the stylesheet for the tabs then the paintEvent does not seem to override the color. I had a similar ticket opened previously but now redefined my requirements.
I really would appreciate any help you can provide.
paintEvent(QPaintEvent * /event/)
{QStylePainter painter(this); QStyleOptionTab opt; for (int i = 0; i < count(); i++) { initStyleOption(&opt, i); painter.save(); if (i == changeColorTabIndex) { if (clearTabBackground == false) { TENA::Console::CustomTabBar::setStyleSheet(""); painter.fillRect(tabRect(i), QColor(255, 255, 0)); //create a yellow background (does not work with a stylesheet defined for a background color for the tabs. } } painter.drawControl(QStyle::CE_TabBarTabShape, opt); //sets tab shape painter.drawControl(QStyle::CE_TabBarTabLabel, opt); //sets tab text painter.restore(); }
}
-
One other question, when I don't use a stylesheet, after I paint the tab yellow, the color seems to bleed above the tab borders. Is there a way I can fix that?
painter.fillRect(tabRect(i), QColor(255, 255, 0)); //create a yellow background
This is what it looks like.
https://www.screencast.com/t/jZXMhELBVRuNPlease any help would be appreciated.