QPainter -draw a diagram and get data from it
for my project i need draw a diagram from model, and allow the user to edit it.
Here is an example:
Rectangles will be read from model so user won't be able to add them. Circles mean input and outputs for tasks (probably also will be read from model )
And what i need is to let user to add/delete an arrow from one circle to another and to get information about all connections in a list:
circle1- circle 2
circle 2- circle 4
This is possible to be done with QPainter?
if yes, can you provide me with some tutorials especially the part with user drawing and getting data from image?
I would use the "Graphics View Framework":/doc/qt-4.8/graphicsview.html classes. You will use [[doc:QGraphicsView]] and it's friends [[doc:QGraphicsScene]] and [[doc:QGraphicsItem]] (and subclasses).
This example will be the best to start with - http://doc.qt.nokia.com/4.7-snapshot/graphicsview-diagramscene.html
Hmm... previous developer tried to implement something like this, but he didn't succeed.
Now i have a piece of code that looks like that tutorial and i think I'll come back with more specific question.
Andre, amban thanks a lot for your help :)
Hello, i came back with other question:
I've managed to draw the rectangle with inputs:
Now i'm interested if i can figure out which circle was clicked.
A circle is clicked if the distance of the click position to the center of the circle is smaller (or equal) to the radius of the circle, e.g.
@(click.x-circle.x)^2 + (click.y-circle.y)^2 <= circle.radius^2@
But if I'm not mistaken, the GraphicsView-Framework should already contain a simple circle/ellipse item with hit-test etc.
I think it have mouse click event, but the problem is that is one custom item,
that contains a rectangle and 2 circles(not three different objects).
It's a object with boundingRect = (0,0,100,100)
rectangle drawn at (0,25,100,50)
and another 2 circles. I can save that circle's QRect in a list, but how to get pointer position inside the graphics item?