QPushButton qss
时间: 2024-06-12 09:08:20 浏览: 199
QPushButton is a widget in Qt that represents a push button. QSS (Qt Style Sheets) is a styling language used in Qt to customize the appearance of widgets.
To apply QSS to a QPushButton, you can set the stylesheet property of the button using the setStyleSheet() method. The stylesheet property takes a string that contains the CSS-like syntax used in QSS.
Here is an example of styling a QPushButton using QSS:
```python
button = QPushButton("Click me")
button.setStyleSheet("QPushButton { background-color: blue; color: white; border-radius: 5px; }")
```
In this example, the button will have a blue background, white text color, and rounded corners.
You can also use QSS to style different states of the button, such as when it is hovered or pressed. Here is an example:
```python
button.setStyleSheet("""
QPushButton {
background-color: blue;
color: white;
border-radius: 5px;
}
QPushButton:hover {
background-color: lightblue;
}
QPushButton:pressed {
background-color: darkblue;
}
""")
```
In this example, the button will have a light blue background when hovered over, and a dark blue background when pressed.
阅读全文