PDA

View Full Version : setColumnHidden does not hide column



mikrocat
27th January 2016, 07:52
In my software I have a tableview with a model.
While runtime the model changes. Sometimes I want to hide columns, but after I changed the model a third time it does not work anymore.



void MonitorWindow::setColumnsHidden(bool hide){
for (int i = 0; i < myTransducermodel->columnCount(); ++i){
qDebug() << hide << i;
ui->transducerTable->setColumnHidden(i, hide);
qDebug() << "hidden?" << ui->transducerTable->isColumnHidden(i);
}
}
}

The Debug says:
true 0
hidden? false
true 1
hidden? false
true 2
hidden? false
true 3
hidden? false
...

Why is that? Do I miss something when I set a new model?



myTransducermodel->clearColumns();

....

ui->transducerTable->setModel(myTransducermodel);




void TransducerSetModel::clearColumns(){
tableHeaders.clear();
}

ChrisW67
27th January 2016, 20:42
It is possible that the GUI is not updated, and the column hidden, until after the program reaches your event loop. You do not say if the column is actually hidden or what "does not work any more" actually means.

Hiding columns in a view is unrelated to adding/removing columns in the model. As long as the model correctly announces the column changes then the view should follow automatically. Is this a custom model?

mikrocat
28th January 2016, 07:55
Yes it is a custom model and when I look closer I see that the column is actually hidden (did not see that before because the software crashed while runtime). So my problem is that "isColumnHidden(i)" returns false although the column is hidden.

I fixed the crash now but I still don't understand why this is happening