I need to get the vertices of a QPolygonF. This is my code till now
class Example(QtGui.QGraphicsScene):
def block(self):
self.bpoint1 = QtCore.QPointF(150 , 150)
self.bpoint2 = QtCore.QPointF(200 , 150)
self.bpoint3 = QtCore.QPointF(200 , 200)
self.bpoint4 = QtCore.QPointF(150 , 200)
self.bproto = QtGui.QPolygonF([self.bpoint1 , self.bpoint2 , self.bpoint3 , self.bpoint4])
self.block = QtGui.QGraphicsPolygonItem()
self.block.setPolygon(self.bproto)
self.block.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
My block becomes now movable , and I need to get the new vertices every time , my block is moved.How do I do it? I tried self.block.boundingRect() , but it gives me the same RectF . Could some-one help me out.
QPolygonjust derives fromQVector, so just use the normal array accessors. But they will be in local coordinates, so they need to be mapped to scene coordinates (I assume that’s you mean by ‘the new vertices’) – useblock.mapToScene( block.polygon()[i] ).