PDA

View Full Version : Custom QGraphicsItem not showing when boundingRect() center is out of view



Qvaliz
20th October 2014, 15:34
Hello.

I'm making a Diagram (Fluxogram) program and for days I'm stuck with this issue:

I have a custom QGraphicsScene that expands horizontally whenever I place an item to it's rightmost area. The problem is that my custom arrows (they inherit QGraphicsPathItem) disappear from the scene whenever it's boundingRect() center is scrolled off the view. Everytime the scene expands, both it's sceneRect() and the view's sceneRect() are updated as well. I've set ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportU pdate), the item flags QGraphicsItem::ItemIgnoresTransformations and QGraphicsItem::ItemSendsGeometryChanges, setActive(true) on the item as well, and everytime I add an arrow to the scene i call the update(sceneRect()) method. Still, everytime I scroll the view, as soon as the arrow's boundingRect() center moves away from the view, all the arrow disappears. If I scroll back and the boundingRect() center enters the view, all the arrow appears again.

Can someone give me a tip of what I might be missing? I've been using Qt's example project diagramscene as reference, so a lot of my code is similar (the "press item toolButton -> click on the scene" relation to insert items, the way they place the arrows to connect the objects,...).

Here's a minimal running example that can show what my issue is (there's a lot of code so I'll just paste the pastebin links, I don't know if I can use it here, so please let me know if it's not how it should be done, it's just that there's a lot of coding to determine positioning and readjustment of the scene):

Header files: pastebin.com/43Vzkrkq ;
C++ files: pastebin.com/aLuE5Yg4 ;
UI file: pastebin.com/1mHWL0hG

Thanks in advance

Qvaliz
20th October 2014, 17:51
Problem solved, changed inheritance of Arrow from QGraphicsPathItem to QGraphicsItem, and added shape() method (I think I didn't forget anything else).