我有一个包含3行2列的QTableView(在这里我使用了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());
moveRow()
函数,它什么也不会做吗?那么这个函数的想法是什么? - Angie Quijano