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. Overriding Stylesheet settings
QtWS25 Last Chance

Overriding Stylesheet settings

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 444 Views
  • 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.
  • L Offline
    L Offline
    leinad
    wrote on last edited by
    #1

    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();
    }
    

    }

    JonBJ 1 Reply Last reply
    0
    • L leinad

      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();
      }
      

      }

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @leinad
      So far as I am aware (I stand to be corrected) all stylesheet settings override anything (matching) from styles/paint events?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leinad
        wrote on last edited by
        #3

        Thanks, I'll wait and see if someone has any ideas. I hope there is a way :)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leinad
          wrote on last edited by
          #4

          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/jZXMhELBVRuN

          Please any help would be appreciated.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            leinad
            wrote on last edited by
            #5

            I think I figured out the issue, seems the stylesheet had a border if not selected the size was 2px larger which was filled in. One must be careful to look at the stylesheet settings when making custom chnanges.

            1 Reply Last reply
            0

            • Login

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