Qt支持哪些CSS语法,全部举例出来
时间: 2023-06-27 14:01:53 浏览: 68
Qt支持的CSS语法包括:
1. 选择器:`QLabel`, `QPushButton`, `QComboBox`等控件名或者`.class`、`#id`选择器;
2. 属性:`background-color`, `color`, `border`, `font-size`等控件属性;
3. 值:支持各种CSS颜色表示方式,如`#RRGGBB`、`rgb(r, g, b)`、`rgba(r, g, b, a)`等;
4. 伪类:`:hover`、`:checked`等伪类;
5. 嵌套:支持嵌套选择器,如`.container:hover .button{...}`;
6. 继承:支持继承父元素样式,如`font-family: inherit;`;
7. 操作符:支持`+`、`>`、`~`等操作符,如`.container > .button{...}`;
8. 特殊值:支持`initial`、`inherit`、`unset`等特殊值。
示例代码:
```css
QLabel{
font-size: 16px;
color: white;
background-color: #333;
}
QPushButton{
background-color: #f00;
color: #fff;
border: none;
padding: 10px 20px;
}
QComboBox{
color: #333;
border: 1px solid #ccc;
padding: 5px;
}
.container:hover .button{
background-color: #0f0;
}
.button:active{
background-color: #00f;
}
input[type="text"]{
padding: 10px;
border: 1px solid #ccc;
}
button + button{
margin-left: 10px;
}
button:hover ~ span{
color: #f00;
}
button:focus{
outline: none;
}
```