def paintEvent(self, e):
self.paint.begin(self)
self.drawEllipse()
self.end()
def paintEvent(self, e):
self.paint.begin(self)
self.drawEllipse()
self.end()
def mousePressEvent(self,e): self.update() #или self.repaint()
vic57
import sys
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtCore import Qt
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.resize(500,500)
self.show()
def paintEvent(self, e):
self.paint = QPainter()
self.paint.begin(self)
def mousePressEvent(self, e):
if e.buttons() == Qt.LeftButton:
self.update()
self.paint.drawEllipse(e.pos().x(), e.pos().y(), 10,10)
app = QApplication(sys.argv)
w = Example()
sys.exit(app.exec_())
class Example(QWidget): def __init__(self): super().__init__() self.flag = False self.initUI() def initUI(self): self.resize(500,500) self.show() def paintEvent(self, e): if self.flag: self.flag = False self.paint = QPainter() self.paint.begin(self) # draw self.paint.end() def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.flag = True self.update()
vic57Написал вот это
import sys
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtCore import Qt
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.x=10
self.y = 10
def initUI(self):
self.resize(500,500)
self.show()
def paintEvent(self, e):
self.paint = QPainter()
self.paint.begin(self)
self.x += 10
self.y += 10
self.paint.drawEllipse(self.x,self.y, 10, 10)
self.paint.end()
def mousePressEvent(self, e):
if e.buttons() == Qt.LeftButton:
self.update()
app = QApplication(sys.argv)
w = Example()
sys.exit(app.exec_())
vic57
import sys
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtGui import QPainter, QColor, QMouseEvent
from PyQt5.QtCore import Qt
class Example(QWidget):
def __init__(self):
super().__init__()
self.flag = False
self.initUI()
def initUI(self):
self.resize(500,500)
self.show()
def paintEvent(self, e):
if self.flag:
self.flag = False
self.paint = QPainter()
self.paint.begin(self)
self.paint.drawEllipse(self.x, self.y,10,10)
self.paint.end()
def mousePressEvent(self, e):
if e.button() == Qt.LeftButton:
self.flag = True
self.x=e.pos().x()
self.y=e.pos().y()
self.update()
app = QApplication(sys.argv)
w = Example()
sys.exit(app.exec_())
vic57Понял, спасибо, буду пробовать.
ai
vic57Спасибо, чекну. Уже написал то, что нужно было через QImage
Hizakoвообще для таких вещей лучше QGraphicsScene использовать
import sys from PyQt5.QtWidgets import QWidget, QApplication from PyQt5.QtGui import QPainter, QColor, QMouseEvent, QImage from PyQt5.QtCore import Qt class Example(QWidget): def __init__(self): super().__init__() self.flag = False self.initUI() def initUI(self): self.resize(500,500) self.image = QImage(self.width(), self.height(), QImage.Format_ARGB32) self.image.fill(QColor(255,255,255)) self.show() def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.flag = True self.paint = QPainter(self.image) self.ellips(e) def paintEvent(self, e): paint = QPainter(self) paint.drawImage(0,0, self.image) def mouseMoveEvent(self, e): if self.flag: print(e.pos()) self.ellips(e) def ellips(self,e): self.paint.setBrush(QColor('black')) self.paint.drawEllipse(e.pos(), 10,10) self.update() app = QApplication(sys.argv) w = Example() sys.exit(app.exec_())