Форум сайта python.su
import sys from PyQt5.QtWidgets import QApplication, QWidget, QFrame from PyQt5.QtGui import QColor, QPainter, QImage from PyQt5.QtCore import Qt class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.resize(500,500) self.frame = QFrame(self) self.frame.resize(400,200) self.frame.move(50,200) self.frame.setStyleSheet('QWidget {Background-color: %s}'% QColor('white').name()) self.image = QImage(200,200, QImage().Format_ARGB32) self.paint = QPainter(self.image) self.show() def paintEvent(self, e): paint = QPainter(self.frame) paint.drawImage(0,0,self.image) def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.goEllipse(e) def mouseMoveEvent(self, e): self.goEllipse(e) def goEllipse(self, e): self.paint.setBrush(QColor('black')) self.paint.drawEllipse(e.pos(), 10, 10) self.frame.update() app = QApplication(sys.argv) w = Example() sys.exit(app.exec_())
Офлайн
не так надо
import sys from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import Qt class Frame(QFrame): def __init__(self,parent=None): QFrame.__init__(self,parent) self.resize(400,200) self.setStyleSheet('QWidget {Background-color: %s}'% QColor('white').name()) self.pix = QPixmap(400,200) self.pix.fill(QColor(0,0,0,0)) def paintEvent(self, e): p = QPainter(self) p.drawPixmap(0,0,self.pix) def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.goEllipse(e) def mouseMoveEvent(self, e): self.goEllipse(e) def goEllipse(self, e): p = QPainter(self.pix) p.setBrush(QColor('green')) p.drawEllipse(e.pos(), 10, 10) self.update() class W(QWidget): def __init__(self,parent=None): QWidget.__init__(self,parent) self.frame = Frame(self) self.frame.move(50,200) app = QApplication(sys.argv) w = W() w.resize(500,500) w.show() sys.exit(app.exec_())
Офлайн
Теперь понял, спасибо
Офлайн