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 set last(right) chunk radius of QProgressBar with QSS ?
Qt 6.11 is out! See what's new in the release blog

How to set last(right) chunk radius of QProgressBar with QSS ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 1.3k 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.
  • joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by joeQ
    #1

    As we know, in QTabBar can set firts and last tab QSS, like below QSS:

    QTabBar::tab {
        color:blue;
    }
    
    /** first and last set color red. */
    QTabBar::tab:first {
        color:red;
    }
    
    QTabBar::tab:last {
        color:red;
    }
    

    my QProgressBar is horizontal, And I want the right(last) chunk has border-top-right-radius and border-bottom-right-radius.

    But, It failed:

    QProgressBar {
        border: 1px solid gray;
        border-radius: 4px;
        text-align: center;
        height:8px; 
        font-size:1px;
    }
    
    QProgressBar::chunk {
        width: 10px;
        /*border-top-right-radius: 4px;*/ // not good
        /*border-bottom-right-radius: 4px;*/
        background-color: rgb(0,65,153);
    }
    
    /** failed */
    QProgressBar::chunk:last { // or right
        width: 10px;
        border-top-right-radius: 4px;
        border-bottom-right-radius: 4px;
        background-color: rgb(0,65,153);
    }
    

    if QSS not, I will try reimplement QProgressBar::paintEvent.

    Just do it!

    joeQJ 1 Reply Last reply
    0
    • joeQJ joeQ

      As we know, in QTabBar can set firts and last tab QSS, like below QSS:

      QTabBar::tab {
          color:blue;
      }
      
      /** first and last set color red. */
      QTabBar::tab:first {
          color:red;
      }
      
      QTabBar::tab:last {
          color:red;
      }
      

      my QProgressBar is horizontal, And I want the right(last) chunk has border-top-right-radius and border-bottom-right-radius.

      But, It failed:

      QProgressBar {
          border: 1px solid gray;
          border-radius: 4px;
          text-align: center;
          height:8px; 
          font-size:1px;
      }
      
      QProgressBar::chunk {
          width: 10px;
          /*border-top-right-radius: 4px;*/ // not good
          /*border-bottom-right-radius: 4px;*/
          background-color: rgb(0,65,153);
      }
      
      /** failed */
      QProgressBar::chunk:last { // or right
          width: 10px;
          border-top-right-radius: 4px;
          border-bottom-right-radius: 4px;
          background-color: rgb(0,65,153);
      }
      

      if QSS not, I will try reimplement QProgressBar::paintEvent.

      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by joeQ
      #2

      I save my problem, not use QSS. I reimplement QProgressBar::paintEvent. Share for you.

      If someone knows how to use QSS to work it out. can reply me. Thank u.

      void ProgressBar::paintEvent(QPaintEvent *event)
      {
          QPainter painter(this);
          painter.setRenderHint(QPainter::Antialiasing,true);
      
          QRect ret = this->rect();
      
          QPen pen;
          int x,y,w,h;
      
          w=1;
          pen.setWidth(w);
          pen.setColor(Qt::gray);
          painter.setPen(pen);
      
          QRect arcRect;
          arcRect = QRect(0,0,ret.height(),ret.height());
          int startAngle = 90 * 16;
          int spanAngle  = 180 * 16;
          painter.drawArc(arcRect,startAngle,spanAngle);
      
          arcRect = QRect(ret.width()-ret.height(),0,ret.height(),ret.height());
          startAngle = 270 * 16;
          spanAngle  = 180 * 16;
          painter.drawArc(arcRect,startAngle,spanAngle);
      
          QPoint p1(ret.height()/2,0);
          QPoint p2(ret.width()-ret.height()/2,0);
          painter.drawLine(p1,p2);
      
          p1 = QPoint(ret.height()/2,ret.height());
          p2 = QPoint(ret.width()-ret.height()/2,ret.height());
          painter.drawLine(p1,p2);
      
          int len = ret.width()/maximum();
          x = y = 0;
          w = h = ret.height();
         
          QColor col = QColor(0,65,153);
          int val = value();
          for(int i=0; i < val; i++){
              QPainterPath path;
              x = len*i;
              path.addEllipse(x,y,w,h);
              painter.fillPath(path,col);
          }
      
          painter.fillRect(QRect(h/2,0,x,h),col);
      }
      
      

      Just do it!

      1 Reply Last reply
      2

      • Login

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