diff --git a/mainwindow.cpp b/mainwindow.cpp index 49c879f..fe4eca6 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -52,14 +52,18 @@ MainWindow::MainWindow(QWidget *parent) firstColMenu = new QMenu(this); QAction* addRowAboveAction = firstColMenu->addAction(tr("↑ 向上添加一行")); QAction* addRowBelowAction = firstColMenu->addAction(tr("向下添加一行 ↓")); + QAction* delRowAction = firstColMenu->addAction(tr("删除")); connect(addRowAboveAction, &QAction::triggered, this, &MainWindow::onAddRowAboveActionTriggered); connect(addRowBelowAction, &QAction::triggered, this, &MainWindow::onAddRowBelowActionTriggered); + connect(delRowAction, &QAction::triggered, this, &MainWindow::onDelRowActionTriggered); firstRowMenu = new QMenu(this); QAction* addColAboveAction = firstRowMenu->addAction(tr("← 向左添加一列")); QAction* addColBelowAction = firstRowMenu->addAction(tr("向右添加一列 →")); + QAction* delColAction = firstRowMenu->addAction(tr("删除")); connect(addColAboveAction, &QAction::triggered, this, &MainWindow::onAddColAboveActionTriggered); connect(addColBelowAction, &QAction::triggered, this, &MainWindow::onAddColBelowActionTriggered); + connect(delColAction, &QAction::triggered, this, &MainWindow::onDelColActionTriggered); } @@ -156,6 +160,20 @@ void MainWindow::onAddColBelowActionTriggered() } } +void MainWindow::onDelRowActionTriggered() +{ + QTableWidget* tableWidget = ui->tableWidget; + int currentRow = tableWidget->currentRow(); + tableWidget->removeRow(currentRow); +} + +void MainWindow::onDelColActionTriggered() +{ + QTableWidget* tableWidget = ui->tableWidget; + int currentColumn = tableWidget->currentColumn(); + tableWidget->removeColumn(currentColumn); +} + void MainWindow::showProgressDialog(const QString& labelText, int minimum, int maximum) { progressDialog = new QProgressDialog(labelText, "Cancel", minimum, maximum, this); diff --git a/mainwindow.h b/mainwindow.h index 44ddbba..71678b1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,6 +35,8 @@ private slots: void onAddRowBelowActionTriggered(); void onAddColAboveActionTriggered(); void onAddColBelowActionTriggered(); + void onDelRowActionTriggered(); + void onDelColActionTriggered(); private: Ui::MainWindow *ui;