New*_*oon 3 qt qtableview qstandarditemmodel qt4.8 qt5
我有一个QTableView3 行 2 列。(这里我使用的是QStandardItemModel)。我想在单击 QPushButton 时向上/向下移动一行。如何在 中向上/向下移动一行QTableView?
感谢您的回复 vahancho。我已经尝试使用QAbstractItemModel::moveRow,但它不起作用:
int currentRow = ui->tableView->currentIndex().row();
QModelIndex sourceParent = ui->tableView->model()->index(ui->tableView->selectionModel()->currentIndex().row(),0);
QModelIndex destinationParent = ui->tableView->model()->index(ui->tableView->selectionModel()->currentIndex().row()+1,0);
ui->tableView->model()->moveRow(sourceParent,currentRow, destinationParent,destinationParent.row());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10063 次 |
| 最近记录: |