[PyQt] Resize a QGraphicsItem with the mouse

Pedro Paulo pedropaulobmjr at hotmail.com
Wed Dec 23 06:26:56 GMT 2015


down votefavoriteAfter put a rectangle 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.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_())Thanks! 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20151223/5c447073/attachment.html>


More information about the PyQt mailing list