Re: Qt View adds empty rows
Re: Qt View adds empty rows
I am having a similar issue.
Code:
--- mainwindow.cpp ----
this->drive_ = new Drive(driveName, this);
this->ui->tableView->setModel(this->drive_);
this->ui->treeView->setModel(this->drive_->tagTree_);
QObject::connect(this
->ui
->treeView,
SIGNAL(clicked
(const QModelIndex
&)),
this,SLOT(recalculate()));
QObject::connect(this
->ui
->treeView,
SIGNAL(viewReleased
()),
this->ui->tableView,SLOT(reset()));
QObject::connect(this
->ui
->treeView,
SIGNAL(viewReleased
()),
this->ui->tableView,SLOT(scrollToTop()));
... unrelated code ...
void MainWindow::recalculate() {
QModelIndexList selection = this->ui->treeView->selectionModel()->selectedIndexes();
this->drive_->recalculate(selection);
}
--- drive.cpp ----
return results_.size();
}
recalculate() is called whenever a new item in the treeView is clicked. It changes the underlying model for the tableView at which point its reset() and scrollToTop() slots are called.
Say, for example, there are 25 items in the view before recalculate is called. If the result of the recalculation has 5 items, the tableView will show the information for the 5 items in the model and 20 empty rows. Apparently the reset doesn't remove those rows. Is there any way for these rows to be removed?
rowCount() is defined as the size of the set of results returned by a recalculation.
Thanks!
Re: Qt View adds empty rows
If your custom model does not emit the relevant signals when adjusting the row count then the view has no way to know the row count has changed. Since we cannot see your custom model code we are hard pressed to see the errors.
You are resetting the view not the model, so only the selections, current item and visual position of the view are changed. This does not cause the view to assume the row or column count has changed.
Re: Qt View adds empty rows
Thanks for the help! My implementation of recalculate() in drive never called beginInsertRows(), endInsertRows(), beginRemoveRows() or endRemoveRows() so, like you had said, the view never knew that there was a change in the number of rows.