So I need the user to be able to customise the tabs completely, I.E. right click on each tab and be able to bring up a colour palette which will allow them to change the colour of that individual tab.
To do this I've re-implemented the paintEvent function within QTabBar like many other posts have suggested, however, I just can't seem to get the tabs to actually change colour...
Currently I'm just running through each tab and changing all the QPalette properties to yellow.
The text of the tab changes to yellow BUT nothing else does!
Code for paintEvent:
protected:
void paintEvent(QPaintEvent *e) {
QStylePainter painter(this);
QStyleOptionTab opt;
for (int i = 0; i < count(); i++)
{
initStyleOption(&opt, i);
opt.palette.setColor(QPalette::Button, QColor("yellow"));
opt.palette.setColor(QPalette::Base, QColor("yellow"));
opt.palette.setColor(QPalette::Window, QColor("yellow"));
opt.palette.setColor(QPalette::AlternateBase, QColor("yellow"));
opt.palette.setColor(QPalette::BrightText, QColor("yellow"));
opt.palette.setColor(QPalette::ButtonText, QColor("yellow"));
opt.palette.setColor(QPalette::Highlight, QColor("yellow"));
opt.palette.setColor(QPalette::Text, QColor("yellow"));
opt.palette.setColor(QPalette::WindowText, QColor("yellow"));
opt.palette.setColor(QPalette::Background, QColor("yellow"));
opt.palette.setColor(QPalette::Foreground, QColor("yellow"));
opt.palette.setColor(QPalette::ToolTipBase, QColor("yellow"));
opt.palette.setColor(QPalette::ToolTipText, QColor("yellow"));
painter.drawControl(QStyle::CE_TabBarTabShape, opt);
painter.drawControl(QStyle::CE_TabBarTabLabel, opt);
}
}
As I said, the text changes to yellow but the background doesn't, according to http://doc.qt.io/archives/qt-4.8/qpalette.html#ColorRole-enum they are all the enums available for use yet none of them seem to change the background colour.
Any help will be greatly appreciated.
Cheers.
EDIT:
It seems to work when I change the tab shape to triangular, however again I don't want this. Is this just a bug in Qt?
QTabWidget Props:
TabWidget* centralTab = new TabWidget();
centralTab->setTabPosition(QTabWidget::South);
centralTab->setTabShape(QTabWidget::Triangular);
centralTab->setMovable(true);
m_mainWindow->setCentralWidget(centralTab);
repaint()
. Do you? – Mikhail