0
votes

I'm developing a small Qt application similar to the DiagramScene example. I have subclassed QGraphicsView instead of QGraphicsScene. My view is zooming in and out with the mouseWheel, I can drag it with the mouse and I can add Nodes and Links with clicking.

I click on one Node, (the first end of the line item is set), then move the mouse (the second end of the line is following the mouse cursor), then I click on the second Node and anchor the second end of the line item to this second node.

The problem is, when the view is zoomed in, or I have moved the view, when I click on a Node and move the mouse, the preview of the link is not visible. When I click on the second Node - the link is still not visible. The link between the two Nodes becomes visible only after I zoom out or drag the view to some point and it intersects with the sides of the view.

Any ideas how to fix this? Thank you so much in advance.

1
It sounds like it could be a problem with not handling the different coordinate systems (local / scene / view), but without a code example, it's difficult to say for sure. - TheDarkKnight
@Merlin069 Unfortunately the code is too long or I don't know how to post it correctly(I'm very new to stackoverflow). I have reimplemented the mousePress, move and release events of QGraphicsView and whenever they are triggered I get their coordinates and map them to the scene with mapToScene(event->pos()). I that correct? - Expr
That depends on what you do with those mapped coordinates. Without a code example, I don't know. - TheDarkKnight
@Merlin069 Here`s the code for the events pastebin.com/RYWn18iv - Expr
I've tried the following: 1) Subclassing QGraphicsScene just like in the DiagramScene example 2) Reimplementing the events with different logic 3) Drawing a QGraphicsLineItem for the preview and when you connect it to the second node it is deleted and a Link is drawn from Node A to Node B All of these have the same effect, when I zoom in or drag the scene the Links are not visible until I zoom out a lot. I have to force the View to update itself and show the lines, but it's not working with any function. The only solution I can think of is to zoom out and then zoom in every time I add a link. - Expr

1 Answers

1
votes

I finally fixed it. I was wrong to use data members for the coordinates (also the bounding rect and paint method) of my custom Graphics items. I changed the code using the setPos() function which gives the right coordinates to my items. @Merlin069 thank you, actually your last question got me thinking whether I set the coordinates correctly.