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

[Qt] 在QTableWidget中添加右键菜单 [2013-06-17更新]

2013-06-17 08:20 465 查看
- *.h
#include <QMenu>

QMenu *popMenu;
QAction *actSelect;
QAction *actUnselect;

- *.cpp
popMenu = new QMenu(ui->tw_DL_ConfTable);
actSelect = new QAction("选择", this);
actUnselect = new QAction("取消选择", this);
popMenu->addAction(actSelect);
popMenu->addAction(actUnselect);

connect(ui->tw_DL_ConfTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slot_DL_RcOnTw(QPoint)));
connect(actSelect, SIGNAL(triggered()), this, SLOT(slot_DL_ActSelect()));
connect(actUnselect, SIGNAL(triggered()), this, SLOT(slot_DL_ActUnselect()));

void MainWindow::slot_DL_RcOnTw(QPoint pos)
{
popMenu->exec(QCursor::pos());
}

void MainWindow::slot_DL_ActSelect()
{
...
}

void MainWindow::slot_DL_ActUnselect()
{
...
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Qt QTableWidget QMenu