我想在這樣一個特定的細胞進入編輯模式:QTableView:我如何正確創建一個QModelIndex?
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()
似乎沒有工作。 OMG!
你'指數()'方法實際上並沒有覆蓋任何東西('QModelIndex'與'常量QModelIndex&')。複製粘貼錯誤? – 2012-06-24 08:08:00