1 Attachment(s)
How to draw a special circle pie
Hi everybody.
I've a little problem, i need to draw a circle pie but in a special manner
I want to draw the border of the circle an fill it but not the lines what goes to the centre.
Like in the attached image
I have tried with ellipse but i cannot change the color of the lines to the centre.
Re: How to draw a special circle pie
first draw the pie without border and then draw the arc on top of it of desired length
Re: How to draw a special circle pie
If i have this. How can i set the pen and brush of arc and fill separately?
Code:
#include <QApplication>
#include <QGraphicsPathItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QDebug>
int main( int argc, char **argv )
{
//arc
arc.arcMoveTo(0,0,100,100,45);
arc.arcTo(0, 0,100,100,45, 100);
// fill
fill.arcTo(0,0,100,100,45, 100);
fill.closeSubpath();
// total path
//item with two paths
// scene
scene.setSceneRect(-100, -100, 250.0, 250.0 );
scene.addItem(&item);
view.show();
return app.exec();
}
Re: How to draw a special circle pie
If you use QGraphicsScene simple use QGraphicsEllipseItem and set a proper pen and brush for your painter.
Code:
item->setStartAngle(...);
item->setSpanAngle(...);
item->setPen(Qt::Black);
item
->setBrush
(QColor(255,
150,
50));
Re: How to draw a special circle pie
Quote:
Originally Posted by
Lykurg
If you use
QGraphicsScene simple use
QGraphicsEllipseItem and set a proper pen and brush for your painter.
Code:
item->setStartAngle(...);
item->setSpanAngle(...);
item->setPen(Qt::Black);
item
->setBrush
(QColor(255,
150,
50));
But that gives to me the arc of ellipse with the arc and the two radius black , and i only want the arc to be painted (as the image at the first post)
I need to know if i can change the pen and brush of a QPainterPath
Re: How to draw a special circle pie
Hi,
Quote:
Originally Posted by
parnedo
I need to know if i can change the pen and brush of a
QPainterPath
Try it. If it don't work you can create two QPainterPaths, one for the pie and the other one for the arc. Paint first the pie and then the arc as MrDeath suggested.
Re: How to draw a special circle pie
Quote:
Originally Posted by
^NyAw^
Hi,
Try it. If it don't work you can create two QPainterPaths, one for the pie and the other one for the arc. Paint first the pie and then the arc as MrDeath suggested.
I can't try because as i said i don't know how to change the pen and brush of a QPainterPath
Re: How to draw a special circle pie
I have found a solution.
I post it for any one who needs it.
Class derived from QGraphicsItem:
Code:
painter
->setPen
(QPen(myBrush.
color(),
0));
painter->setBrush(myBrush);
painter->setBackgroundMode(Qt::OpaqueMode);
painter->drawPie(x, y, w,h, angle, degrees);
painter->setPen(myPen);
painter->drawArc(x, y, w,h, angle, degrees);
}