Is it possible to propagate QGraphicsItemGroup
mouse events to child added items?
setHandlesChildEvents(false) is deprecated, and I don't want to use it.
I tried this, but it didn't work:
class MoveItemBase : public QObject, public QGraphicsItem;
bool sceneEvent(QEvent* event) override
{
if (event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
propagateSceneEvent(event);
return true;
}
return QGraphicsItemGroup::sceneEvent(event);
}
void propagateSceneEvent(QEvent* event)
{
for (QGraphicsItem* child : childItems()) {
MoveItemBase* widget = static_cast<MoveItemBase*>(child);
QCoreApplication::sendEvent(widget, event);
}
}
As far as I know and found, there is no direct alternative to setHandlesChildEvents.
I did however find a workaround in this thread on Qt Center Forum: setHandlesChildEvents() obsolete?, where it was suggested to use QGraphicsItem::installSceneEventFilter, which says:
Based on these findings, I made a generic example to implement that: