aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/painting/painter/painter.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/painting/painter/painter.py')
-rw-r--r--examples/widgets/painting/painter/painter.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/examples/widgets/painting/painter/painter.py b/examples/widgets/painting/painter/painter.py
index 49036ae00..2ca078ad9 100644
--- a/examples/widgets/painting/painter/painter.py
+++ b/examples/widgets/painting/painter/painter.py
@@ -9,7 +9,7 @@ from PySide6.QtWidgets import (
QStyle,
QColorDialog,
)
-from PySide6.QtCore import QPoint, Qt, QDir, Slot, QStandardPaths
+from PySide6.QtCore import Qt, Slot, QStandardPaths
from PySide6.QtGui import (
QMouseEvent,
QPaintEvent,
@@ -116,15 +116,17 @@ class MainWindow(QMainWindow):
self.bar = self.addToolBar("Menu")
self.bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self._save_action = self.bar.addAction(
- qApp.style().standardIcon(QStyle.SP_DialogSaveButton), "Save", self.on_save
+ qApp.style().standardIcon(QStyle.SP_DialogSaveButton), # noqa: F821
+ "Save", self.on_save
)
self._save_action.setShortcut(QKeySequence.Save)
self._open_action = self.bar.addAction(
- qApp.style().standardIcon(QStyle.SP_DialogOpenButton), "Open", self.on_open
+ qApp.style().standardIcon(QStyle.SP_DialogOpenButton), # noqa: F821
+ "Open", self.on_open
)
self._open_action.setShortcut(QKeySequence.Open)
self.bar.addAction(
- qApp.style().standardIcon(QStyle.SP_DialogResetButton),
+ qApp.style().standardIcon(QStyle.SP_DialogResetButton), # noqa: F821
"Clear",
self.painter_widget.clear,
)
@@ -136,7 +138,8 @@ class MainWindow(QMainWindow):
self.setCentralWidget(self.painter_widget)
- self.set_color(Qt.black)
+ self.color = Qt.black
+ self.set_color(self.color)
self.mime_type_filters = ["image/png", "image/jpeg"]
@@ -175,19 +178,21 @@ class MainWindow(QMainWindow):
@Slot()
def on_color_clicked(self):
- color = QColorDialog.getColor(Qt.black, self)
+ color = QColorDialog.getColor(self.color, self)
+
if color:
self.set_color(color)
def set_color(self, color: QColor = Qt.black):
+ self.color = color
# Create color icon
pix_icon = QPixmap(32, 32)
- pix_icon.fill(color)
+ pix_icon.fill(self.color)
self.color_action.setIcon(QIcon(pix_icon))
- self.painter_widget.pen.setColor(color)
- self.color_action.setText(QColor(color).name())
+ self.painter_widget.pen.setColor(self.color)
+ self.color_action.setText(QColor(self.color).name())
if __name__ == "__main__":