我试图在我的 QGraphicsItem 子类中实现一个上下文菜单,如下所示:
void ImagePixmapItem::right_clicked(){
qDebug("Got here!");
}
void ImagePixmapItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
QMenu menu;
QAction *removeAction = menu.addAction("Remove");
QAction *markAction = menu.addAction("Mark");
QAction *selectedAction = menu.exec(event->screenPos());
connect(selectedAction, SIGNAL(triggered()),this, SLOT(right_clicked()));
}
我究竟做错了什么?文字“到了!” 永远不会被解雇,此外,我如何修改它以知道从菜单中选择了哪个操作?
谢谢