From a86dfcfe977b5ef8290762146528b63415be06a1 Mon Sep 17 00:00:00 2001 From: Crimson Date: Sat, 24 Feb 2024 21:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E-#5=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=A1=8C/=E5=88=97=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 18 ++++++++++++++++++ mainwindow.h | 2 ++ 2 files changed, 20 insertions(+) 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;