qt python 按钮圆角样式并设置红色
时间: 2023-05-20 10:07:43 浏览: 350
您可以使用Qt的QSS(Qt样式表)来实现圆角按钮和红色背景色,样式代码如下:
QPushButton {
background-color: red;
color: white;
border-radius: 10px;
padding: 6px;
font-size: 16px;
}
您可以在PyQt5中使用这个样式表来创建一个按钮:
```python
from PyQt5.QtWidgets import QWidget, QPushButton
from PyQt5.QtGui import QIcon
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 创建一个 QPushButton 组件
qbtn = QPushButton('按钮', self)
# 设置按钮的图标和提示
qbtn.setIcon(QIcon('web.png'))
qbtn.setToolTip('这是一个按钮')
# 设置按钮的样式表
qbtn.setStyleSheet('''
QPushButton {
background-color: red;
color: white;
border-radius: 10px;
padding: 6px;
font-size: 16px;
}
''')
# 设置按钮的位置和大小
qbtn.resize(qbtn.sizeHint())
qbtn.move(50, 50)
# 设置窗口的位置和大小
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('圆角按钮样式')
self.show()
```
这将创建一个红色的,圆角的 QPushButton 组件,并在中心显示一个白色的“按钮”文字。
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)