8
votes

I am currently doing the following:

QGraphicsScene *scene;
QPen pen;
pen.setColor(color);
scene->addEllipse(x, y, size, size, pen, QBrush(Qt::SolidPattern));

However, this is drawing a black circle with a border of the colour 'color'. How do I draw a fully coloured ellipse?

1

1 Answers

6
votes

QBrush is what controls the fill color of your ellipse. In the code you've provided, you're just giving a brush with a solid pattern (hence the black fill).

If you look at the various QBrush constructors, you'll note that there are several different kinds. The ones you'll likely be most interested in are

QBrush ( Qt::GlobalColor color, Qt::BrushStyle style = Qt::SolidPattern )
QBrush ( const QColor & color, Qt::BrushStyle style = Qt::SolidPattern )

which will allow you do do things like:

scene->addEllipse( x, y, size, size, pen, QBrush(Qt::red) );

or

scene->addEllipse( x, y, size, size, pen, QBrush(QColor("#FFCCDD") );

See Qt's QBrush documentation