Qt World Summit: Submit your Presentation

How to combine stylesheets and custom widget painting?

  • We've got a method to draw text in the QTabBar bold, because there's no provided function for it. However the bar can no longer be customised with a stylesheet, which means the entire application is themable except for the tabbar - and this really stands out!

    How can the two be merged?

    Our custom painting method for reference:

    void TStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
        if (element == QStyle::CE_TabBarTab) {
            QString tabName = mpTabBar->tabData(mpTabBar->tabAt(option->rect.center())).toString();
            QFont font = widget->font();
            bool isStyleChanged = false;
            if (mBoldTabsSet.contains(tabName)||mItalicTabsSet.contains(tabName)||mUnderlineTabsSet.contains(tabName)) {
                isStyleChanged = true;
            QProxyStyle::drawControl(element, option, painter, widget);
            if (isStyleChanged) {
        } else {
            QProxyStyle::drawControl(element, option, painter, widget);

  • Lifetime Qt Champion

    It will not work - either use CSS or a custom Style. Afaics the stylesheet stuff is internal so you can't access it.

Log in to reply