11

次のような特定のセルで編集モードに入ろうとしています:

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()機能していないように見えるため、インデックスが何らかの形で無効であると確信しています。

4

1 に答える 1

14

ああ、神様!地面が私を飲み込む!

行番号は行 0 から始まります。

int r=tm->rowCount(QModelIndex())-1;
QModelIndex id=tm->index(r,ec,QModelIndex());
于 2010-03-22T13:30:07.410 に答える