как поменять вид линии в pyqt

пытаюсь сделать так, чтобы мышка рисовала не сплошной линией, а прерывистой пробовала в параметрах QPen поставить Qt.Dashline, почему то не помогает

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QFileDialog, QColorDialog, QMessageBox, QInputDialog, \
    QWidget, QLabel
from PyQt5.QtGui import QImage, QPainter, QPen, QColor, QPixmap
from PyQt5.QtCore import Qt, QPoint, QSize


class PaintApp(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Paint")
        uic.loadUi('untitled.ui', self)

        self.size = self.label.size()
        canvas = QPixmap(self.size)
        canvas.fill(Qt.white)
        self.label.setPixmap(canvas)
        self.last_x, self.last_y = None, None

        self.brush_color = Qt.black
        self.brush_size = 6

        self.pixmap = QPixmap("1640528610_2-abrakadabra-fun-p-serii-chelovek-na-avu-2.jpg")
        self.label_2.setPixmap(self.pixmap)
        self.label_2.setScaledContents(True)

        self.pushButton.setStyleSheet("appearance: none;"
                                      "border: 0;"
                                      "border-radius: 5px;"
                                      "background: #a83f48;"
                                      "color: #fff;"
                                      "padding: 8px 16px;"
                                      "font-size: 16px;")

        self.pushButton_2.setStyleSheet("border-image: url(C:/Users/user/Desktop/python/"
                                        "97897-3000x2000-rainbow-ombre-background-photo-desktop-hd.jpg);"
                                        "color: black;"
                                        "border-radius: 5px")
        self.pushButton_2.clicked.connect(self.chose_color)

        self.pushButton_3.setStyleSheet("border-image: url(C:/Users/user/Desktop/python/"
                                        "97897-3000x2000-rainbow-ombre-background-photo-desktop-hd.jpg);"
                                        "color: black;"
                                        "border-radius: 5px")
        self.pushButton_3.clicked.connect(self.chose_size)

        self.pushButton.clicked.connect(self.close)

        self.create_menu()

    def chose_size(self):
        new_size, ok = QInputDialog.getInt(self, "Brush Size", "Enter the size:", self.brush_size,
                                           min=1, max=50)
        if ok:
            self.brush_size = new_size

    def chose_color(self):
        new_color = QColorDialog.getColor()
        if new_color.isValid():
            self.brush_color = new_color

    def create_menu(self):
        main_menu = self.menuBar()

        file_menu = main_menu.addMenu("File")
        save_action = QAction("Save", self)
        save_action.setShortcut("Ctrl+S")
        save_action.triggered.connect(self.save_image)
        file_menu.addAction(save_action)

        clear_action = QAction("Clear", self)
        clear_action.setShortcut("Ctrl+C")
        clear_action.triggered.connect(self.clear_image)
        file_menu.addAction(clear_action)

    def save_image(self):
        file_path, _ = QFileDialog.getSaveFileName(self, "Save Image", "",
                                                   "PNG(*.png);;JPEG(*.jpg *.jpeg)")
        if file_path == "":
            return
        self.label.pixmap().save(file_path)

    def clear_image(self):
        canvas = QPixmap(self.size)
        canvas.fill(Qt.white)
        self.label.setPixmap(canvas)

    def mouseMoveEvent(self, e):
        deltaX = self.centralWidget().x() + self.label.x()
        deltaY = self.centralWidget().y() + self.label.y()

        if self.last_x is None:
            self.last_x = e.x() - deltaX
            self.last_y = e.y() - deltaY
            return

        painter = QPainter(self.label.pixmap())
        p = QPen(self.brush_color, self.brush_size, Qt.SolidLine)
        painter.setPen(p)
        painter.drawLine(self.last_x, self.last_y, e.x() - deltaX, e.y() - deltaY)
        painter.end()
        self.update()

        self.last_x = e.x() - deltaX
        self.last_y = e.y() - deltaY

    def mouseReleaseEvent(self, e):
        self.last_x = None
        self.last_y = None


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = PaintApp()
    window.show()
    sys.exit(app.exec_())

Ответы (0 шт):