我正在尝试进入特定单元格的编辑模式,如下所示:
void MainWindow::on_addButton_released() {
tm->addRow();
tableView->scrollToBottom();
int ec=tm->firstWritableColumn();
int r=tm->rowCount(QModelIndex());
QModelIndex id = tm->index(r, ec, QModelIndex());
tableView->setCurrentIndex(id);
tableView->edit(id);
qDebug() << "row:" << r << " col:" << ec << "index:" << id;
}我的模型创建了一个这样的索引:
QModelIndex TableModel::index(int row,int column,QModelIndex parent) const {
Q_UNUSED(parent);
return createIndex(row,column,0);
}调试输出如下所示:
row: 9 col: 1 index: QModelIndex(9,1,0x0,TableModel(0xbf3f50) ) 我相当确定索引在某种程度上是无效的,因为setCurrentIndex()似乎不工作。
发布于 2010-03-22 21:30:07
天哪!地面把我吞没了!
行号从第0行开始,我需要这样做
int r=tm->rowCount(QModelIndex())-1;
QModelIndex id=tm->index(r,ec,QModelIndex());https://stackoverflow.com/questions/2492470
复制相似问题