我有一个QTableView
有 3 行和 2 列。 (这里我使用的是QStandardItemModel
)。我想在单击 QPushButton 时向上/向下移动一行。如何在中向上/向下移动一行QTableView
?
感谢您的回复瓦汉乔。我已经尝试过使用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());
使用 Qt 文档QStandartItemModel
- QStandardItemModel 类 http://doc.qt.io/qt-4.8/qstandarditemmodel.html
takeRow
insertRow
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)