- Qt 5.4.2 Reference Documentation
Header: | #include <QGraphicsItemGroup> |
qmake: | QT += widgets |
Since: | Qt 4.2 |
Inherits: | QGraphicsItem. |
You define itemList
as:
QList<QGraphicsItem *> itemList;
You are then trying to iterate it with:
foreach(QGraphicsItemGroup *item, itemList){
// ...
}
From the documentation you can see that QGraphicsItemGroup inherits from QGraphicsItem. So every QGraphicsItemGroup "is a" QGraphicsItem. But not every QGraphicsItem "is a" QGraphicsItemGroup.
If you want to iterate that itemList then item will have to be a QGraphicsItem, or itemList will have to be a QGraphicsItemGroup. It seems that since you are testing for specific classes then the former is probably what you want.
If you look at the documentation for QGraphicsItem::ItemIsSelectable, it states: -
The item supports selection. Enabling this feature will enable setSelected() to toggle selection for the item. It will also let the item be selected automatically as a result of calling QGraphicsScene::setSelectionArea(), by clicking on an item, or by using rubber band selection in QGraphicsView.
Since QGraphicsItemGroup is derived from QGraphicsItem, I suspect that by default, a QGraphicsItemGroup does not have this flag selected. So, for each group, set this flag and if you only want the groups returned from the rubber band selection, turn off the flags for all the other items.
https://stackoverflow.com/questions/21604159/detecting-clicks-on-a-qgraphicsitemgroup