Page History
...
QGraphicsView is a class with scrolled graph window...
Re-draw widget immediately when its property is changed
When QPushButton is pressed and connected method is called, all button properties stay unchanged until the method. In order to see current changes one has to re-draw widget. For example:
Code Block |
---|
|
Graphics in PyQt4
Code Block |
---|
... self.poi1 = QtCore.QPoint(0,0) self.poi2 = QtCore.QPoint(0,0) self.rect1 = QtCore.QRect() self.rect2 = QtCore.QRect() self.pen1 = QtGui.QPen(QtCore.Qt.black) self.pen2 = QtGui.QPen(QtCore.Qt.white) self.pen1.setStyle(QtCore.Qt.DashLine) self.pen2.setStyle(QtCore.Qt.DashLine) self.pen1.setWidthF(1) self.pen2.setWidthF(1) ... def paintEvent(self, e): super(GUIImage,self).paintEvent(e) qp = QtGui.QPainter() # or QPainter can be defined earlier and use it as qp = self.qp qp.begin(self) #self.drawPixmap(qp) self.drawRect(qp) qp.end() self.update() def setPen(self, qp): self.pen.setStyle(QtCore.Qt.DashLine) self.pen.setWidthF(1) def drawRect(self, qp): if self.r_pixmap == None: return p1x, p1y = self.poi1.x(), self.poi1.y() p2x, p2y = self.poi2.x(), self.poi2.y() R=1 if abs(p2x-p1x) < R : return if abs(p2y-p1y) < R : return self.rect1.setCoords( p1x, p1y, p2x, p2y) self.rect2.setCoords( p1x+1, p1y+1, p2x-1, p2y-1) qp.setPen (self.pen1) qp.drawRect(self.rect1); qp.setPen (self.pen2) qp.drawRect(self.rect2); def drawPixmap(self, qp): if self.r_pixmap != None: qp.drawPixmap(0,0,self.s_pixmap) |
...
Overview
Content Tools