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

Custom Circle Progress Bar

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 5.0k 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.
  • M Offline
    M Offline
    moutasdimitris
    wrote on 9 Sept 2021, 08:11 last edited by moutasdimitris 9 Sept 2021, 08:13
    #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 1 Reply Last reply 9 Sept 2021, 08:13
    0
    • M moutasdimitris
      9 Sept 2021, 08:11

      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 Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 9 Sept 2021, 08:13 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 9 Sept 2021, 08:24 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!

        M 1 Reply Last reply 9 Sept 2021, 08:52
        0
        • M moutasdimitris
          9 Sept 2021, 08:24

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 9 Sept 2021, 08:52 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 9 Sept 2021, 11:54
          0
          • M mrjj
            9 Sept 2021, 08:52

            @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 9 Sept 2021, 11:54 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 9 Sept 2021, 13:56
            0
            • M moutasdimitris
              9 Sept 2021, 11:54

              @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 9 Sept 2021, 13:56 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

              1/6

              9 Sept 2021, 08:11

              • Login

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