新增-#5 添加删除行/列功能

This commit is contained in:
阿甘 2024-02-24 21:58:57 +08:00
parent 5227ceaf5c
commit a86dfcfe97
2 changed files with 20 additions and 0 deletions

View File

@ -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);

View File

@ -35,6 +35,8 @@ private slots:
void onAddRowBelowActionTriggered();
void onAddColAboveActionTriggered();
void onAddColBelowActionTriggered();
void onDelRowActionTriggered();
void onDelColActionTriggered();
private:
Ui::MainWindow *ui;