PDA

View Full Version : Resize a QGraphicsItem with the mouse



Pedro Monteiro
27th December 2015, 07:29
After put a rectangle (http://imgur.com/E1zYfwJ) in a QGraphicsScene and make it movable with the mouse, how could I resize it with the mouse?

If no one knows an answer, a example could be good too, I'm developing in Python using PYQt4, but the example can be in C++.

My simplified code:



import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication(sys.argv)

grview = QGraphicsView()
scene = QGraphicsScene()
scene.setSceneRect(0, 0, 512, 512)

scene.addPixmap(QPixmap('01.png'))
grview.setScene(scene)

item = QGraphicsRectItem(0, 0, 300, 150)

pen = QPen(Qt.darkMagenta)
pen.setWidth(4)
item.setPen(pen)

item.setFlag(QGraphicsItem.ItemIsMovable)
scene.addItem(item)

grview.fitInView(scene.sceneRect(), Qt.KeepAspectRatio)

grview.show()

sys.exit(app.exec_())