程序里做了右键菜单
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); // 右键使能 menu = new QMenu(ui->tableWidget); copySelect = new QAction(menu); copySelect->setText("复制选中"); copyAll = new QAction(menu); copyAll->setText("复制全部"); menu->addAction(copyAll); menu->addAction(copySelect); //右键位置 QObject::connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenuPos(QPoint))); //右键事件 QObject::connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(MenuSlot(QAction*)));
void FormPZCX::MenuSlot(QAction *action) //函数作用:根据行为判断当前所做的事 { if(action == copyAll) { //复制全部 JCode::FZTableWidget(ui->tableWidget); } if (action == copySelect) {//复制选中 JCode::FZTableWidgetSelect(ui->tableWidget); } } void FormPZCX::showMenuPos(QPoint)//函数作用:右键菜单显示位置 { menu->exec(QCursor::pos()); }
发表评论