在Qt软件中用QSS帮我写几个有3D感的按键
时间: 2024-02-20 09:00:24 浏览: 126
好的,以下是几个使用QSS实现3D效果的按钮样式:
1. 立体感按钮:
```css
QPushButton {
border: 1px solid #333;
border-radius: 5px;
padding: 5px;
color: #fff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #666, stop: 1 #333);
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
}
QPushButton:hover {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #999, stop: 1 #666);
}
QPushButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #333, stop: 1 #666);
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
```
2. 凸起按钮:
```css
QPushButton {
border: 1px solid #333;
border-top-color: #ccc;
border-left-color: #ccc;
border-radius: 5px;
padding: 5px;
color: #fff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #666, stop: 1 #333);
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5) inset;
}
QPushButton:hover {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #999, stop: 1 #666);
border-top-color: #fff;
border-left-color: #fff;
}
QPushButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #333, stop: 1 #666);
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5) inset;
}
```
3. 漂浮按钮:
```css
QPushButton {
border: 1px solid #333;
border-radius: 5px;
padding: 5px;
color: #fff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #666, stop: 1 #333);
box-shadow: 0px 3px 10px rgba(0, 0, 0, 0.5);
}
QPushButton:hover {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #999, stop: 1 #666);
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.5);
}
QPushButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #333, stop: 1 #666);
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.5);
}
```
这些样式可以通过调整颜色和阴影参数来适应不同的场景,希望能帮到您。
阅读全文