PDA

View Full Version : How to paint with QLinearGradient in QLabel?



programmer251
30th April 2012, 04:01
Hello every body...

That's my 2 rd thread on this forum.

I have a pretty newbie question, how to paint with QLinearGradient on QLabel?

I have the code, but I don't know how to paint on label_3...


QLinearGradient gradient(50,100,300,350);
gradient.setColorAt(0.0,Qt::white);
gradient.setColorAt(0.1,Qt::black);
gradient.setColorAt(1.0,Qt::green);
gradient.start();
Should I set parent, or child or something like that ? ? ?

sorry for newbie questions.


Thanks.

ChrisW67
1st May 2012, 00:11
Assuming you are trying to produce some sort of custom widget then you should sub-class QLabel, reimplement QWidget::paintEvent() and do your painting there. See the Analogue Clock Example.

You may be able to achieve a similar result using style sheets, particularly the background property

programmer251
2nd May 2012, 00:16
thanks. :))