Qt sets the font color in qlabe.

Source: Internet
Author: User

 

(In visual mode, the modification is very simple. Select the label to be modified and then, as shown in)



For other information, see the following description.

Http://blog.csdn.net/qter_wd007/article/details/5919006

Recently, some people asked how to use qt4 to set the font color in the qlabel.

In fact, this is a common problem. There are several methods: setpalette (), style sheet, qstyle, and simple HTML styles. The following is a summary.

 

First, use setpalette () as follows:

 

...

Qlabel * label = new qlabel (TR ("Hello QT! "));

Qpalette PE;

PE. setcolor (qpalette: windowtext, QT: White );

Label-> setpalette (PE );

Qpalete: window, usually the background color of the window part;

Qpalette: windowtext, which usually refers to the foreground view without a window;

Qpalette: base indicates the background color of text input window components (such as qtextedit and qlinedit.

Qpalette: Text, used together with qpalette: Base, refers to the foreground color of the text input window part;

Qpalette: button, which indicates the background color of the Button widget;

Qpalette: buttontext, which refers to the foreground color of the Button widget.


Second, use the style sheet as follows:

 

Setstylesheet (font-color: Your color );

 

// For more information, see QT assistant.

 

Third, the use of qstyle has a good example of qstyle in QT demo. For more information, see.

 

Fourth, some simple HTML formats are used:

 

Qlabel * label = new qlabel (TR ("Hello QT! "));

Qlabel * label = new qlabel ("<H2> <I> Hello </I> <font color = Red> QT! </Font> </H2> ");

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.