Reputation: 153
I've been working on a game in C++/Qt. My game consists of some custom Classes with a pointer to a custom class picture that inherits from QGraphicsItem. The Picture class also contains a pointer back to the instance of the custom class.
Now when I add the items with the picture class to a QGraphicsScene, I want to get the selected items from that Scene, and read the pointers to their custom classes, but I don't really know a way to do this. I tried using QGraphicsScene->selectedItems() but this only returns a QList of GraphicsItems :S
Could anybody help me with this? Thanks in advance
Upvotes: 1
Views: 604
Reputation: 12931
You can use dynamic_cast
to cast the QGraphicsItem
s to your custom class that inherits from QGraphicsItem when you get a list of selected items in the scene.
Example:
QList<QGraphicsItem*> list = scene->selectedItems();
for(int i = 0; i < list.length(); i++)
{
CustomItem *item = dynamic_cast<CustomItem*>(list[i]);
}
Upvotes: 2