qtableview (libqt) how do I correctly create a QModelIndex

Posted by Chris Camacho on Stack Overflow See other posts from Stack Overflow or by Chris Camacho
Published on 2010-03-22T13:19:46Z Indexed on 2010/03/22 13:31 UTC
Read the original article Hit count: 377

Filed under:
|

I'm trying to enter edit mode on a specific cell like this

void MainWindow::on_addButton_released(void) {
    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;
}

my model creates an index like this

QModelIndex TableModel::index(int row,int column,QModelIndex parent) const {
    Q_UNUSED(parent);
    return createIndex(row,column,0);
}

the debug output looks like this

row: 9  col: 1 index: QModelIndex(9,1,0x0,TableModel(0xbf3f50) )  

I'm fairly sure that the index is somehow invalid as setCurrentIndex doesn't seem to be working

© Stack Overflow or respective owner

Related posts about qt

Related posts about qtableview