View Full Version : QGraphicsPathItem for a path made of rects with control points?

21st December 2010, 10:19

I need to draw a path of rectangles. This path must have control points (on the top part of the rectangles) and let me modify its position. I have been checking QGraphicsPathItem and seems ok for the drawing of the path, but couldn't find anything related to the control points. Is this a suitable class for my needs? Any other built-in solution or should I build my own class?.

Edit: Would it be a good option to have a GraphicsPathItem for the drawing and add QGraphicsRectItem for the control points? I think I could do this iterating through all the path elements.

Thanks in advance,

21st December 2010, 23:04

Do you mean a number of rectangles that must be arranged along a line or curve ?

If you just create all the rectangles yourself (add them to the scene with addRect()), you can allow the user to drag the rectangles themselves (no need for control points). You can store the rectangles in a list, so you can keep track of the position of each rectangle and update all positions dynamically when 1 rectangle is dragged around.

You can also create a QGraphicsItem subclass (e.g. CRectanglePath) with a method to add a rectangle. The rectangle would become a child of the CRectanglePath object. If you want control points, you can turn these on and off with a method of CRectanglePath, and CRectanglePath will then add new QGraphicsItem objects (e.g. a small yellow circle) for each rectangle to act as control point. These are set to be draggable. When one is dragged, the CRectanglePath object can then update the position of all its other child rectangles. The CRectanglePath object can have a method for reading and writing rectangle positions, e.g. to a string using a QXmlStreamReader/Writer.

I started out doing something with some of these functionalities some time ago. You can check it out here : Mindmapping widget (http://www.qtcentre.org/threads/35243-Mindmapping-widget?p=164436#post164436). Hope the attachment works, some people reported it didn't.

Best regards,