diff options
| author | Christian Tismer <tismer@stackless.com> | 2022-01-26 12:49:43 +0100 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2022-01-26 16:47:13 +0000 |
| commit | b61f735acd8fa2e43a68d7d90f977d8f1506052a (patch) | |
| tree | 9a5f4fb9debe1d7d51119ea9e169e58bc47bc62f /examples/widgets/draganddrop | |
| parent | dc2046124f132ba0187d1bff97364448288b1cd6 (diff) | |
examples: Turn most QPainter instances into context managers
After the new context manager is in place, most of
the examples benefit from moving QPainter into a
`with` statement.
The comments concerning PyPy could be removed, again.
[ChangeLog][PySide6] The examples are updated to use the new
context manager for QPainter.
Task-number: PYSIDE-535
Change-Id: Idf7e1f734d549ed663383ffbb2416297ebb1e0c7
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples/widgets/draganddrop')
| -rw-r--r-- | examples/widgets/draganddrop/draggableicons/draggableicons.py | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.py b/examples/widgets/draganddrop/draggableicons/draggableicons.py index 5fe6590e7..b3b4a56e5 100644 --- a/examples/widgets/draganddrop/draggableicons/draggableicons.py +++ b/examples/widgets/draganddrop/draggableicons/draggableicons.py @@ -139,10 +139,8 @@ class DragWidget(QFrame): # .copy() is important: python is different than c++ in this case temp_pixmap = pixmap.copy() - painter = QPainter() - painter.begin(temp_pixmap) - painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127)) - painter.end() + with QPainter(temp_pixmap) as painter: + painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127)) child.setPixmap(temp_pixmap) @@ -152,9 +150,6 @@ class DragWidget(QFrame): child.show() child.setPixmap(pixmap) - # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3. - painter.end() - if __name__ == "__main__": app = QApplication(sys.argv) |
