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. QTabBar "Paint Event" & Stylesheet Conflicting
QtWS25 Last Chance

QTabBar "Paint Event" & Stylesheet Conflicting

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtabbarpaint eventstylesheetqtabwidgetdraw objects
2 Posts 2 Posters 348 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.
  • N Offline
    N Offline
    Narutoblaze
    wrote on 30 Nov 2023, 14:29 last edited by
    #1

    I am painting my own tabbar to create the blinking effect but i also have to style the tabbar so i also have this stylesheet but it is removing the blinking effect is there a work around to this?

    I have found few ways searching the internet but i don't know it will work in my case and also not sure how to apply it.

    These Are :

    QAnimation

    Dynamically change stylesheet

    My Paint Function :

    void customTabBar::paintEvent(QPaintEvent *event)
    {
        QTabBar::paintEvent(event);
        QStylePainter painter(this);
        QStyleOptionTab opt;
    
        customTabWidget *parentTabWidget = qobject_cast<customTabWidget *>(parentWidget());
        for (int i = 0; i < count(); i++) {
            initStyleOption(&opt, i);
    
            if (AlertList.contains(parentTabWidget->widget(i)) && on == true) {
                opt.palette.setColor(QPalette::Button, Qt::red);
                painter.drawControl(QStyle::CE_TabBarTab, opt);
            }
    
            if (PinList.contains(parentTabWidget->widget(i))) {
                opt.palette.setColor(QPalette::Button, Qt::blue);
                painter.drawControl(QStyle::CE_TabBarTab, opt);
            }
        }
    }
    

    My stylesheet :

    QTabBar::tab {
        margin-left: 2px;
        background: #373638;
        color: #f8f8f2;
        padding-left: 20px;
        padding-right: 20px;
        border-bottom-color: transparent;
        padding-top: 1px;
        padding-bottom: 1px;
        border-radius: 2px;
    }
    
    QTabBar::tab:selected{
        margin-left: 2px;
        background-color: #535455;
        color: #f8f8f2;
        padding-left: 20px;
        padding-right: 20px;
        padding-top: 1px;
        padding-bottom: 1px;
        border-bottom-color: transparent;
        border-radius: 2px;
    }
    
    C 1 Reply Last reply 30 Nov 2023, 18:10
    0
    • C Christian Ehrlicher referenced this topic on 30 Nov 2023, 18:06
    • N Narutoblaze
      30 Nov 2023, 14:29

      I am painting my own tabbar to create the blinking effect but i also have to style the tabbar so i also have this stylesheet but it is removing the blinking effect is there a work around to this?

      I have found few ways searching the internet but i don't know it will work in my case and also not sure how to apply it.

      These Are :

      QAnimation

      Dynamically change stylesheet

      My Paint Function :

      void customTabBar::paintEvent(QPaintEvent *event)
      {
          QTabBar::paintEvent(event);
          QStylePainter painter(this);
          QStyleOptionTab opt;
      
          customTabWidget *parentTabWidget = qobject_cast<customTabWidget *>(parentWidget());
          for (int i = 0; i < count(); i++) {
              initStyleOption(&opt, i);
      
              if (AlertList.contains(parentTabWidget->widget(i)) && on == true) {
                  opt.palette.setColor(QPalette::Button, Qt::red);
                  painter.drawControl(QStyle::CE_TabBarTab, opt);
              }
      
              if (PinList.contains(parentTabWidget->widget(i))) {
                  opt.palette.setColor(QPalette::Button, Qt::blue);
                  painter.drawControl(QStyle::CE_TabBarTab, opt);
              }
          }
      }
      

      My stylesheet :

      QTabBar::tab {
          margin-left: 2px;
          background: #373638;
          color: #f8f8f2;
          padding-left: 20px;
          padding-right: 20px;
          border-bottom-color: transparent;
          padding-top: 1px;
          padding-bottom: 1px;
          border-radius: 2px;
      }
      
      QTabBar::tab:selected{
          margin-left: 2px;
          background-color: #535455;
          color: #f8f8f2;
          padding-left: 20px;
          padding-right: 20px;
          padding-top: 1px;
          padding-bottom: 1px;
          border-bottom-color: transparent;
          border-radius: 2px;
      }
      
      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 30 Nov 2023, 18:10 last edited by
      #2

      The style always wins as written here: https://doc.qt.io/qt-6/stylesheet.html#overview

      "Style sheets are applied on top of the current widget style,"

      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
      1

      1/2

      30 Nov 2023, 14:29

      • Login

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