答案 0 :(得分:1)
添加QMenu作为窗口小部件的成员。在.h:
#include <QMenu>
#include <QAction>
.....
QMenu menu;
在构造函数中:
QAction* action=new QAction("save",this);
connect(action,SIGNAL(triggered()),this,SLOT(save()));
menu.addAction(action);
QAction* action2=new QAction("clear",this);
connect(action2,SIGNAL(triggered()),this,SLOT(clear()));
menu.addAction(action2);
setContextMenu(&menu);