1 设置QtreeWidget控件属性设置:
将contextMenuPolicy属性要设置为:CustomContextMenu
2 建立信号槽:
connect(ui.treeWidget_IndexManage, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(SlotCustomContextMenuRequested(const QPoint&)));
3 在槽函数中写代码:(创建右键删除菜单)
QAction *pDelAction = new QAction(“删除”,this);
QMenu *popMenu = new QMenu(this);//定义⼀个右键弹出菜单
popMenu->addAction(pDelAction);//往菜单内添加QAction 该action在前⾯⽤设计器定义了
popMenu->exec(QCursor::pos());//弹出右键菜单,菜单位置为光标位置
QtreeWidget添加右键菜单
最新推荐文章于 2024-04-25 15:33:38 发布