Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to combine stylesheets and custom widget painting?
Qt 6.11 is out! See what's new in the release blog

How to combine stylesheets and custom widget painting?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 597 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vadi2
    wrote on last edited by
    #1

    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)) {
                painter->save();
                font.setBold(mBoldTabsSet.contains(tabName));
                font.setItalic(mItalicTabsSet.contains(tabName));
                font.setUnderline(mUnderlineTabsSet.contains(tabName));
                isStyleChanged = true;
                painter->setFont(font);
            }
    
            QProxyStyle::drawControl(element, option, painter, widget);
    
            if (isStyleChanged) {
                painter->restore();
            }
    
        } else {
            QProxyStyle::drawControl(element, option, painter, widget);
        }
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved