[Interest] Draw multiple rectangles in a QGraphicsItem using the mouse

Michael Sué sue at sf.mpg.de
Tue Oct 20 08:42:44 CEST 2015


Hi,

> I would like to create a Graphical User Interface which allows the user to draw as many rectangles as he wants on an image using the left button of his mouse.

In the mousePressEvent you would create a QGraphicsRectItem, add it to the graphics scene and make it "the current one".

In mouseMoveEvent you would change the current rect's edge according to the mouse position.

The code in "paint" seems not really necessary as graphics items added to the graphics scene know how to draw themselves.

Your image you would draw in the virtual drawBackground method of your graphics view.

- Michael.





More information about the Interest mailing list