Solved Adding Items to Reimplemented QGraphicsScene
-
I have reimplemented QGraphicsScene to a class called MGraphicsScene as I would like to disable moving any items in case the QGraphicsScene is used for a certain purpose that I have made available through variable Mode. I have the following code for this:
void MGraphicsScene::addItem(QGraphicsItem *Item) { if (Mode == INSPECTOR) Item->setFlag(QGraphicsItem::ItemIsMovable, false); QGraphicsScene::addItem(Item); }
On top of this, I have reimplemented MGraphicsScene to a class called StructuralScene. I am trying to add items to such StructuralScene by using the following code:
void StructuralScene::onAddedPort(PortDefinition *Connector) { PortDiagram *New = new PortDiagram(Connector); New->setZValue(-150); addItem(New); }
PortDiagram is a subclass of QGraphicsObject.
For some reason however, the PortDiagram items are not added at all to the scene. I have checked this by inspecting the result of QGraphicsScene::items() after performing StructuralScene::onAddedPort, but this list is indeed empty. Any ideas what is wrong here, i.e., why the items are not added to the scene?
-
The problem stays if I remove the MGraphicsScene::addItem method completely. So, in which direction should I be looking for potential errors?
-
I found the problem: I forgot to set the scene for my view! How stupid...
-
@ModelTech
Well on the bright side, you found it yourself. :) -
Yes :) But I only found it because I was trying to access the scene in a context menu elsewhere ;)
-
Hehe, well all productive programmers will have some sort of whoops from time to time. :)