【发布时间】:2013-09-09 08:14:31
【问题描述】:
我有一个QTableView,有 3 行 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());
【问题讨论】:
-
它不起作用,因为它是一个你必须自己实现的虚函数。
-
neuronet,谢谢您的回复。那么,你是说这个函数(
moveRow())如果你自己不实现它就什么都不做? .那么这个函数的思路是什么?
标签: qt qt5 qtableview qt4.8 qstandarditemmodel