central = new Qwidget (this), Setcentralwidget (Central), Central->setautofillbackground (True);central-> Setwindowopacity (1); label = new Qlabel (TR ("This is a song, please remember it, do not forget"), central); label2 = new Qlabel (central); Label2->move ( Label2->resize (500,50); Label->move (500,50); label->resize (in); Qfont ft;ft.setpointsize, Label->setfont (ft); Label->setattribute (qt::wa_translucentbackground); label2- >setfont (ft); Label2->setattribute (qt::wa_translucentbackground); str = TR ("This is a song, please remember it, do not forget"); count=1; Qtimer *timer = new Qtimer (this), Connect (timer, SIGNAL (timeout ()), this, SLOT (Paint ())), Timer->start (1000);
void Label_test::p aint () {count++;update (); Qdebug () <<count;} void Label_test::p aintevent (qpaintevent *e) {qlineargradient Lineargrad (qpointf (+), qpointf (200, 200)); Lineargrad.setcolorat (0, qt::red); Lineargrad.setcolorat (0.5, Qt::yellow); Lineargrad.setcolorat (1, Qt::green); Qbrush Brush (Lineargrad); Qpalette Palette;palette.setbrush (qpalette::windowtext, brush); int length = Str.length (); if (Count > Length) {count = 1;} Label2->setpalette (palette);//label->settext (""); QString s = Str.mid (0, Count); Label2->settext (s); Label2->show ();}
The main idea is to use two Qlabel controls, and the second Qlabel control to redraw the first qlabel each time.
Repaint will automatically call the PaintEvent function
QT Display lyrics Gradient