在paintEvent函数外实现(即,不使用paintEvent函数):
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class myMainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.image = QPixmap(1000, 1000)
self.image.fill(Qt.transparent)# 填充透明色
self.setWindowTitle("简单的画板")
self.pos_xy = []
self.pen = QPen(Qt.black, 2, Qt.SolidLine)
self.painton = True
self.imageLabel = QLabel()
self.setCentralWidget(self.imageLabel)
self.imageLabel.setPixmap(self.image)