Qt Style Sheets

Source: Internet
Author: User
Use the QT Style sheets to create a personalized UI interface.

Style sheets is made up of a series of style rules. A style rule is composed of a selector selector and a declaration declaration these two parts. Selector explains which widgets the rule works on, declaration explains what properties to set on these widgets. For example:

Qpushbutton, Qlineedit  {color:red; Background-color:white}

In the above style rule, Qpushbutton, Qlineedit is a two selector, with a comma connection in the middle. {color:red; Background-color:white} is a declaration declaration, inside Curly braces is a series of property:value pairs, which are concatenated with semicolons. This rule indicates that Qpushbutton and Qlineedit and their subclasses need to use red as their foreground color, and use white as their background color.

If the controls are more or more complex, we can set style Sheet by using the QSs file. First we create a new text document, the suffix name to QSS, and then use a text editor such as Notepad to open it, we set the style sheets to write in and then save it. The QSs file created by this routine is called STYLESHEETDEMO.QSS, so we only need to write the following lines of code in the program to make the style sheets we write in the QSs file work:

QFile file (":/qss/stylesheetdemo.qss");
File.Open (qfile::readonly);
Qtextstream Filetext (&file);
QString stylesheet = Filetext.readall ();
Ui->tab->setstylesheet (stylesheet);

In the program, STYLESHEETDEMO.QSS is added to the resource file, where Ui->tab is the first tab page in Tabwidget.

Common settings in the QSs file:

Qgroupbox {
	Background-image:url (:/pics/background.png); 
	border-radius:30px;
}
Qlabel {
	color:gray;
}
Qlineedit {
	background:qradialgradient (cx:0, cy:0, radius:1,
            fx:0.5, fy:0.5, stop:0 White, stop:1 Rgba (0,190 , 0, 60%));
	border-radius:9px;
}
qcheckbox:checked {
	color:green;     
}
qcheckbox::indicator {
      width:25px;
      height:25px;
}
qcheckbox::indicator:checked {
     	image:url (:/pics/checkbox.gif);
}
qradiobutton{
      Spacing

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.