QT Display lyrics Gradient

Source: Internet
Author: User

       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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.