// menuInst和treeView全为类成员变量(指针),teeView已生成
在构造函数中
{
setupUi(this);
menuInst = new QMenu(this);
QAction *act = menuInst->addAction(tr("Chat Invite"));
connect(act, SIGNAL(triggered()),
this, SLOT(onChatInviteTriggered()));
act = menuInst->addAction(tr("Chat Close"));
connect(act, SIGNAL(triggered()),
this, SLOT(onChatCloseTriggered()));
treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(treeView,
SIGNAL(customContextMenuRequested(const QPoint &)),
this,
SLOT(onContactViewCustomContextMenuRequested(const QPoint &)));
}
void ListenDockWidget::onContactViewCustomContextMenuRequested(const QPoint &pos)
{
menuInst->popup(treeView->mapToGlobal(pos));
}