[Qt-interest] How to fill QLabel Circles with different color

Stephan Rose kermos at somrek.net
Wed Jan 7 20:57:50 CET 2009


On Wed, 2009-01-07 at 19:36 +0000, Arun wrote:
> Normally what we will do to fill the color in widget with 
> paintEvent is by using setPen & setBrush, as shown below.
> 
> void paintEvent(QPaintEvent *event)
> {
> QPainter p(this);
> p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap));
> p.setBrush(QBrush(Qt::black, Qt::SolidPattern));
> p.drawEllipse(0, 0, width() - 1, height() - 1);
> p.end();
> QLabel:aintEvent(event);
> }
> Here in the above shown example I am filling all the circles with black color.
> 
> But my problem is I have to fill the each circle with 
> random/differnt colors taken from some other functionality. 
> I cannot pass that color into this paintEvent function. 
> So I have to do some other things which fills different
> colors for these circles.
> 
> So how to fill solid pattern colors for these 
> different paintEvent drawn circles ?

Well you are already subclassing QLabel so why not just add a member
variable to your class for the color to use?

Stephan





More information about the Qt-interest-old mailing list