第三步,添加通过“行列”对话框,设置表格行列数的功能。
C:\Users\Minwei\Projects\Qt\Sheet\rowcoldialog.h:
xxxxxxxxxx
141...
2class RowColDialog : public QDialog
3{
4 ...
5public:
6 ...
7 void setRowCount(int rowCount);
8 int getRowCount(void);
9
10 void setColumnCount(int columnCount);
11 int getColumnCount(void);
12 ...
13};
14...
C:\Users\Minwei\Projects\Qt\Sheet\rowcoldialog.cpp:
xxxxxxxxxx
211...
2void RowColDialog::setRowCount(int rowCount)
3{
4 ui->m_spinRow->setValue(rowCount);
5}
6
7int RowColDialog::getRowCount(void)
8{
9 return ui->m_spinRow->value();
10}
11
12void RowColDialog::setColumnCount(int columnCount)
13{
14 ui->m_spinCol->setValue(columnCount);
15}
16
17int RowColDialog::getColumnCount(void)
18{
19 return ui->m_spinCol->value();
20}
21...
C:\Users\Minwei\Projects\Qt\Sheet\sheetwindow.cpp:
xxxxxxxxxx
161...
2
3...
4void SheetWindow::on_m_actRowCol_triggered()
5{
6 RowColDialog dlg(this);
7 dlg.setRowCount(m_model->rowCount());
8 dlg.setColumnCount(m_model->columnCount());
9
10 if (dlg.exec() == QDialog::Accepted)
11 {
12 m_model->setRowCount(dlg.getRowCount());
13 m_model->setColumnCount(dlg.getColumnCount());
14 }
15}
16...
运行效果如图所示: