Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw an ellipse filled with a certain colour?

Tags:

c++

qt

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?

like image 380
zebra Avatar asked Dec 19 '11 20:12

zebra


1 Answers

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

like image 114
Chris Avatar answered Nov 11 '22 20:11

Chris