Hey!
i have these two functions in my QGraphicView class:
if (item
&&item
->flags
().
testFlag(QGraphicsItem::ItemIsSelectable)) menu.addAction(tr("Remove Item"),this, SLOT(deleteDoor(item)));
menu.addAction(tr("Add Door Selector"), this, SLOT(createDoor()));
menu.addAction(tr("Add Cage"), this, SLOT(markCage()));
menu.exec(event->globalPos());
}
scene.removeItem(item);
}
void VideoWidget::contextMenuEvent(QContextMenuEvent * event) {
QGraphicsItem *item = itemAt(event->pos());
QMenu menu;
if (item&&item->flags().testFlag(QGraphicsItem::ItemIsSelectable))
menu.addAction(tr("Remove Item"),this, SLOT(deleteDoor(item)));
menu.addAction(tr("Add Door Selector"), this, SLOT(createDoor()));
menu.addAction(tr("Add Cage"), this, SLOT(markCage()));
menu.exec(event->globalPos());
}
void VideoWidget::deleteDoor(QGraphicsItem *item) {
scene.removeItem(item);
}
To copy to clipboard, switch view to plain text mode
This contextMenu is called, if you click somewhere in the View. If there is an item at the view's mouse click position the action "remove item" is added to the context menu. The Problem is, i dont know how to connect the QAction properly to the deleteDoor(QGraphicItem*) slot, because i need to pass the items pointer as a parameter, but the action only emits triggered()
So What would you suppose is the best way to remove the item from the Scene by calling the context menu's action?
Bookmarks