您的位置:首页 > 编程语言 > Qt开发

Qt creator 创建鼠标右键菜单 (不新建类)

2014-04-22 17:06 1096 查看

界面



步骤

打开你的界面文件并选中你要添加右键的控件,选择“CustomContextMenu”



右键选择“转到槽...” -> customContextMenuRequested



插入下面代码即可

void MainWindow::on_listWidget_customContextMenuRequested(const QPoint &pos)
{
static QMenu *qMenu = NULL;
if (qMenu == NULL)
{
qMenu = new QMenu(ui->listWidget);
QAction* closePaneAction = new QAction("&Close",this);
connect(closePaneAction, SIGNAL(triggered()), this, SLOT(close()));

qMenu->addAction(closePaneAction);
}

qMenu->exec(QCursor::pos()); //在鼠标点击的位置显示鼠标右键菜单
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: