我想在这样一个特定的细胞进入编辑模式: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