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. Custom Circle Progress Bar
Qt 6.11 is out! See what's new in the release blog

Custom Circle Progress Bar

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 6.9k Views 2 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.
  • M Offline
    M Offline
    moutasdimitris
    wrote on last edited by moutasdimitris
    #1

    Hi guys, I want to develop the progress bar from the image down below using C++. Any idea?
    69120c2c-7ba7-427e-bbb3-965491ca738a-image.png

    J.HilkJ 1 Reply Last reply
    0
    • M moutasdimitris

      Hi guys, I want to develop the progress bar from the image down below using C++. Any idea?
      69120c2c-7ba7-427e-bbb3-965491ca738a-image.png

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @moutasdimitris
      sure, google gave me this
      https://stackoverflow.com/a/42794690/15422846


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moutasdimitris
        wrote on last edited by
        #3

        @J-Hilk I have seen this post again but for me, it's hard to develop on Qt using C++. So I asked here!

        mrjjM 1 Reply Last reply
        0
        • M moutasdimitris

          @J-Hilk I have seen this post again but for me, it's hard to develop on Qt using C++. So I asked here!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @moutasdimitris

          Hi
          But it has a class to reuse ?

          The most important part is the paintEvent.
          So you could start looking at that and ask if anything is hard to understand.

          M 1 Reply Last reply
          0
          • mrjjM mrjj

            @moutasdimitris

            Hi
            But it has a class to reuse ?

            The most important part is the paintEvent.
            So you could start looking at that and ask if anything is hard to understand.

            M Offline
            M Offline
            moutasdimitris
            wrote on last edited by
            #5

            @mrjj Partially I managed to draw this but for different window sizes the dashed parts are 3 or more but I want 10 arcs and 10 spaces.

            M 1 Reply Last reply
            0
            • M moutasdimitris

              @mrjj Partially I managed to draw this but for different window sizes the dashed parts are 3 or more but I want 10 arcs and 10 spaces.

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #6

              @moutasdimitris
              Not so easy ;)

              void Widget::paintEvent(QPaintEvent* ev)
              {
                  QPainter painter(this);
                  painter.setRenderHint(QPainter::Antialiasing,true);
                  QRect rec=rect();
              
                  int minWidth=qMin(rec.width(),rec.height())/2;
                  int thickness=minWidth/6;
                  rec.adjust(thickness,thickness,-thickness,-thickness);
                  minWidth=qMin(rec.width(),rec.height())/2;
              
                  QConicalGradient gradient(rec.center(),90);
                  gradient.setColorAt(0,Qt::transparent);
                  gradient.setColorAt(.5,QColor(25,180,255));
                  
                  QPainterPath path;
                  path.addEllipse(rec.center(),minWidth,minWidth);
                  QPainterPath clipPath;
                  clipPath.addEllipse(rec.center(),minWidth-thickness,minWidth-thickness);
                  path=path.subtracted(clipPath);
                  
                  int segNum=8;   // number of segments
                  int radius=minWidth+1;
                  int t=thickness/4;  // inter segment width
                  int cx=rec.center().x();
                  int cy=rec.center().y();
                  
                  for(int i=0; i<segNum; i++)
                      {
                      // calculate inter segment pos
                      float angle=180.0/segNum*i+90;
                      float cos1=qCos(qDegreesToRadians(angle));
                      float sin1=qSin(qDegreesToRadians(angle));
                      float cos2=qCos(qDegreesToRadians(angle+180));
                      float sin2=qSin(qDegreesToRadians(angle+180));
                      float x1=cx+radius*cos1;
                      float y1=cy-radius*sin1;
                      float x2=cx+radius*cos2;
                      float y2=cy-radius*sin2;
                      
                      QPainterPath line;
                      line.moveTo(x1-sin1*t,y1-cos1*t);
                      line.lineTo(x1+sin1*t,y1+cos1*t);
                      line.lineTo(cx,cy);
                      line.lineTo(x2-sin2*t,y2-cos2*t);
                      line.lineTo(x2+sin2*t,y2+cos2*t);
                      path=path.subtracted(line); // subtract inter segment
                      //painter.fillPath(line,Qt::white);
                      }
                  
                  painter.fillPath(path,gradient);
                  
              }
              
              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