Tôi đang cố gắng để vào chế độ chỉnh sửa trên một tế bào cụ thể như thế này:QTableView: làm cách nào để tôi tạo đúng 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;
}
Mô hình của tôi tạo ra một chỉ số như thế này:
QModelIndex TableModel::index(int row,int column,QModelIndex parent) const {
Q_UNUSED(parent);
return createIndex(row,column,0);
}
Sản lượng debug trông như thế này:
row: 9 col: 1 index: QModelIndex(9,1,0x0,TableModel(0xbf3f50))
Tôi khá chắc chắn rằng chỉ mục bằng cách nào đó không hợp lệ vì setCurrentIndex()
dường như không hoạt động.
của bạn 'index() 'phương pháp không thực sự ghi đè lên bất cứ điều gì (' QModelIndex' vs' const QModelIndex & '). Sao chép-dán lỗi? –