The stacked style sheet (CSS) can be flexibly used in QT, and its syntax is similar to CSS. Because of the flexibility of html css, you can easily design the desired appearance for the QT interface.
Examples of the use of style sheets for qt4.8 parts here: http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qlineedit
Style Sheet user manual here: http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#font
I wrote a lot of details on the official website, so I won't say much about it. I just copied it and I didn't mean to say what I should pay attention.
1. Set the style sheet for each sub-Object
The widget's object name calls the style sheet, as shown below:
ComboBox-> setstylesheet ("qcombobox {border: 1 pxsolidgray; border-radius: 3px; padding: 1px18px1px3px ;}");
In this way, the style sheet is set separately for this part. It should be noted that when the setstylesheet function is used to set a style sheet for ComboBox again, the previously set style sheet does not work, that is, the style is replaced by the currently defined effect.
If you want to define a style for all controls (such as all qcomboboxes on the Interface), you can use qapp to set the style.
2. Use qapp to set a style sheet
Qapp is a global object. After you use it to set a style table, the component will have a fixed style. Of course, when you use a sub-object to call the setstylesheet function, only the style set in the function will be changed, other styles will not change.
For example:
Qapp-> setstylesheet ("qpushbutton {border: 2 rows; border-radius: 6px; Background-color: # e3eaa5; Min-width: 80px;} qcombobox {border: 1 pxsolidgray; border-radius: 3px; padding: 1px18px1px3px;} qlineedit {border: 1 pxsolidgray; border-radius: 5px; padding: 08px; selection-Background-color: darkgray ;}");
This sentence defines the style of buttons, drop-down boxes, and row edit boxes. All the three components on the interface are displayed according to the style defined in the box. If you want to modify the style of one of the Child parts, you can directly call setstylesheet to overwrite the style you need, and retain others, such
Pushbutton-> setstylesheet ("qpushbutton {background-color: red ;}");
In this way, only the background color of the button is changed, and the size of the border that qapp defines remains unchanged.
Note: When many components are deployed together, sometimes qapp is used first, and then unexpected results are displayed when the child parts are set. In this case, style sheet settings are directly performed on the Child parts without qapp, each time you set all the style table elements, the individual settings will overwrite the previous style table.