QPushButton 如何通过样式表设置按钮导角
时间: 2024-05-09 08:15:47 浏览: 9
可以使用 `border-radius` 属性来设置 QPushButton 的导角,具体操作如下:
```cpp
// 设置样式表
button->setStyleSheet("QPushButton { border-radius: 10px; }");
```
上述代码将 QPushButton 的导角设置为 10px。
除了使用样式表,也可以通过继承 QPushButton 并重写 `paintEvent()` 函数来自定义导角的绘制。
相关问题
如何设置QPushButton的样式表
可以使用setStyleSheet()函数来设置QPushButton的样式表,例如:
```
QPushButton {
background-color: blue;
color: white;
font-size: 16px;
border-radius: 5px;
}
QPushButton:hover {
background-color: lightblue;
}
```
这个样式表会将按钮的背景颜色设置为蓝色,字体颜色设置为白色,字体大小设置为16px,边框圆角设置为5px。当鼠标悬停在按钮上时,背景颜色会变成浅蓝色。你可以根据自己的需要来设置样式表。
QPushbutton 高度样式表
QPushbutton 的高度可以通过样式表进行设置,可以使用如下代码:
```
QPushButton {
height: 40px;
}
```
这样就可以将 QPushbutton 的高度设置为 40 像素。如果需要设置不同状态下的高度,可以使用下面的代码:
```
QPushButton {
height: 40px;
}
QPushButton:hover {
height: 50px;
}
QPushButton:pressed {
height: 60px;
}
```
这样就可以在不同的状态下设置不同的高度,例如鼠标悬停时高度为 50 像素,按钮被按下时高度为 60 像素。