PDA

View Full Version : How to draw a special circle pie



parnedo
2nd July 2009, 01:50
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.

nish
2nd July 2009, 02:49
first draw the pie without border and then draw the arc on top of it of desired length

parnedo
2nd July 2009, 11:11
If i have this. How can i set the pen and brush of arc and fill separately?


#include <QApplication>
#include <QGraphicsPathItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QDebug>

int main( int argc, char **argv )
{
QApplication app(argc, argv);

//arc
QPainterPath arc(QPoint(50,50));
arc.arcMoveTo(0,0,100,100,45);
arc.arcTo(0, 0,100,100,45, 100);

// fill
QPainterPath fill(QPoint(50,50));
fill.arcTo(0,0,100,100,45, 100);
fill.closeSubpath();

// total path
QPainterPath total = fill.united(arc);

//item with two paths
QGraphicsPathItem item(total);
item.setPen(QPen(QColor(0, 0, 0), 5));
item.setBrush(QBrush(QColor(100, 100, 100)));

// scene
QGraphicsScene scene;
scene.setSceneRect(-100, -100, 250.0, 250.0 );
scene.addItem(&item);

QGraphicsView view( &scene );
view.show();
return app.exec();
}

Lykurg
2nd July 2009, 13:10
If you use QGraphicsScene simple use QGraphicsEllipseItem and set a proper pen and brush for your painter.


QGraphicsEllipseItem *item = new QGraphicsEllipseItem();
item->setStartAngle(...);
item->setSpanAngle(...);
item->setPen(Qt::Black);
item->setBrush(QColor(255, 150, 50));

parnedo
2nd July 2009, 16:19
If you use QGraphicsScene simple use QGraphicsEllipseItem and set a proper pen and brush for your painter.


QGraphicsEllipseItem *item = new QGraphicsEllipseItem();
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

^NyAw^
2nd July 2009, 16:48
Hi,


I need to know if i can change the pen and brush of a QPainterPath (http://doc.trolltech.com/latest/qpainterpath.html)

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.

parnedo
2nd July 2009, 18:26
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

parnedo
3rd July 2009, 15:25
I have found a solution.
I post it for any one who needs it.

Class derived from QGraphicsItem:


void TArcEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget){

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);
}