本文主要是介绍Qt: QTableWidget,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
给Table安装过滤器,添加右键删除选中行
bool FitPlaneDialog::eventFilter(QObject* watched, QEvent* event) {//对my_table_widget添加右键菜单if (watched == ui->my_table_widget) {if (event->type() == QEvent::ContextMenu) {QMenu menu(ui->my_table_widget);QAction* delete_action = menu.addAction(tr("删除"));QAction* selected_action = menu.exec(QCursor::pos());if (selected_action == delete_action) {QModelIndexList selected_rows = ui->my_table_widget->selectionModel()->selectedRows();for (int i = selected_rows.size() - 1; i >= 0; i--) {ui->my_table_widget->removeRow(selected_rows.at(i).row());}}}}return QDialog::eventFilter(watched, event);
}
这篇关于Qt: QTableWidget的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!