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