pyqt repaint
时间: 2023-09-24 19:06:11 浏览: 114
PyQt QListWidget修改列表项item的行高方法
In PyQt, you can use the `repaint()` method to update the appearance of a widget or the entire application.
The `repaint()` method schedules a paint event for the widget, which will cause the widget to be repainted at the next available opportunity.
Here's an example of how to use `repaint()` to update the appearance of a widget:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.button = QPushButton('Click me', self)
self.button.clicked.connect(self.on_button_clicked)
def on_button_clicked(self):
self.button.setText('Clicked!')
self.repaint()
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
```
In this example, we create a `QPushButton` and connect its `clicked` signal to a method that changes the text of the button and calls `repaint()` to update its appearance.
When the button is clicked, its text changes to "Clicked!" and the widget is repainted to reflect the change.
阅读全文