PDA

View Full Version : Drawing rectangles in QT



andreahmed
25th February 2012, 10:12
I would like to draw squares and withing them, small circles that can be connected to other squares in other squares by a polyline or so.

I would like to know how to do that in QT.

Attached an image for more illustration.image
7434

wayfaerer
25th February 2012, 19:16
Use a QGraphicsScene/View, then subclass QGraphicsItem to make the squares with circles. Do you want the user to be able to connect notes by dragging, or do you want to connect them yourself programmatically?

andreahmed
25th February 2012, 21:11
Thanks.
Yea, I would like the user to connect the nodes by dragging.

wayfaerer
25th February 2012, 22:24
Then you should reimplement some protected functions in your QGraphicsItems, particularly mousePressEvent, mouseMoveEvent, and mouseReleaseEvent. mousePressEvent would notify the item to draw a line (probably another QGraphicsItem), from the initial click location to mouseMoveEvent's current location. mouseReleaseEvent could call scene().itemAt() to determine which node is at the mouse release location. Something like that.

ChrisW67
26th February 2012, 07:03
The Diagram Scene Example would be a good starting place

andreahmed
26th February 2012, 20:08
How to draw circles around triangles? and those circles can be connected to other circles ?!