last day (14 days later) » 

8:42 PM
0
A: Custom circular progressbar in Qt

ddriverI don't see what's the problem here, you can use QPainterPath and adding a full or partial arc path to it, then draw the path via QPen using a Qt::DotLine style. If the stock dotted line doesn't work for you, there is the option to specify a custom pattern via: void QPen::setDashPattern(const Q...

 
I've tried before that but that is not what I want
 
This is how you achieve the result from the image.
 
I've only used dashedPattern but it gave me some circles in 360. They were bigger then I expected
Don't have a experience with QPainterPath
 
@elgolondrino see QPainterPath::arcTo() functions, which allow you to specify begin and end angle of the arc. doc.qt.io/qt-4.8/qpainterpath.html#arcTo
 
As I understand first I'm supposed to create rectangle e.g. Trapezium... and give coordinates to that function?
What about button inside that progressBar, any ideas?
 
8:42 PM
I don't know what you are talking about, the format of usage is arcTo(sizeRect, startAngle, lengthAngle) - the size rect is the size of the circle, the rest is self explanatory. You obviously need to do more learning before you rush into making things. Read the documentation on QPainter and related types.
 
@ddriver I've tried but I'm not able to do that can you help me?
 
what have you tried?
 
QPainterPath
 
what code
 
I'm not able to draw that little trapeziums with angle in the circle
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
QPainterPath path;
path.arcTo(QRectF(50, 50, 10, 200), 20, -40);
QPen pen(Qt::black, 1);
p.setPen(pen);
p.drawPath(path);
 
8:55 PM
I'd suggest not to make them trapezoid
it is barely visible
it will be significantly more complicated to draw the dashes as trapezoids
you'd basically need to use trigonometry and calculate the position and angle for every one
and draw a separate trapezoid in the exact position
normal dashed line with custom pattern will achieve 99% of the result much easier
 
Can you help?
 
I am too busy to write your code for you sorry
I told you how to do it
don't be lazy, learn, try, fail and learn from failing, until you succeed
 
Okay, then can you please help me with this code:
int width = qMin(this->width(), this->height());

QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);

int outerRadius = (width-1)*0.5;
int innerRadius = (width-1)*0.5*0.38;

int capsuleHeight = outerRadius - innerRadius;
int capsuleWidth = (width > 32 ) ? capsuleHeight *.23 : capsuleHeight *.35;
int capsuleRadius = capsuleWidth/3;
int m_angle = 0;
for (int i=0; i<12; i++)
{
QColor color = Qt::black;
color.setAlphaF(1.0f - (i/12.0f));
p.setPen(Qt::NoPen);
p.setBrush(color);
p.save();
p.translate(rect().center());
It draws circle with rounded rectangles but I need the one which looks like in the image ...
 
9:10 PM
rotating the painter is a good idea
I was about to suggest the same
you need to modify the values for the radius and iterations
 
I've done it but I want trapezoid like rectangle
 

last day (14 days later) »