QTableWidget如何添加右键功能?
作者:互联网
1.首先初始化
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
//右键
m_tabMenu = new QMenu(ui->tableWidget);
action= new QAction("展示最近数据",this);
m_tabMenu->addAction(action);
connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slot_DL_RcOnTw(QPoint)));
connect(action,SIGNAL(triggered(bool)),this,SLOT(slotActionInsert()));
2. 然后激活右键
void MainWindow::slot_DL_RcOnTw(QPoint pos)
{
m_tabMenu->exec(QCursor::pos());
}
3.接着就可以添加功能
标签:QTableWidget,QPoint,tableWidget,ui,右键,tabMenu,action,添加 来源: https://blog.csdn.net/sinat_20962951/article/details/122220845