Форум сайта python.su
import sys from PyQt5.QtWidgets import QApplication, QWidget, QFrame, QPushButton, QGridLayout, QSplitter from PyQt5.QtGui import QPixmap, QColor, QPainter from PyQt5.QtCore import Qt class Splitter(QSplitter): def __init__(self, napr, frame): super().__init__(napr) self.frame = frame def resizeEvent(self, e): self.frame.setSize(self.width(), self.height()) class Frame(QFrame): def __init__(self, parent): super().__init__(parent) self.parent = parent self.initUI() def initUI(self): self.pix = QPixmap(300,300) self.pix.fill(QColor('white')) 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.drawEllipse(e.pos(), 10, 10) self.update() def setSize(self, w, h): self.setSize(w,h) self.pix = QPixmap(w,h) class W(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.resize(400,800) self.frame = QFrame(self) self.splitter = Splitter(Qt.Horizontal, self.frame) self.splitter.addWidget(self.splitter) layout = QGridLayout() layout.addWidget(self.splitter, 0,0) self.setLayout(self.layout) self.show() app = QApplication(sys.argv) w=W() sys.exit(app.exec_())
Офлайн
все делаешь через … матчасть учи
Офлайн
vic57Спасибо, посмотрю. Но не знаете как поступить именно в этом случае?
все делаешь через … матчасть учи
Офлайн
так как то
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,400) self.setStyleSheet('QWidget {Background-color: %s}'% QColor('white').name()) self.pix = QPixmap() def paintEvent(self, e): p = QPainter(self) p.drawPixmap(0,0,self.pix) def mouseMoveEvent(self, e): p = QPainter(self.pix) p.setBrush(QColor('red')) p.drawEllipse(e.pos(), 5, 5) self.update() def resizeEvent(self,e): self.pix = QPixmap(self.size()) self.pix.fill(QColor(0,0,0,0)) class W(QWidget): def __init__(self,parent=None): QWidget.__init__(self,parent) self.frame = Frame() self.lbl = QLabel('Label') splitter = QSplitter(Qt.Vertical) splitter.addWidget(self.frame) splitter.addWidget(self.lbl) grid = QGridLayout(self) grid.addWidget(splitter,0,0) app = QApplication(sys.argv) w = W() w.resize(500,500) w.show() sys.exit(app.exec_())
Офлайн