Reputation: 763
Well, here is the problem:
I construct a QTableView
and use the setModel(myModel)
method which bind the model myModel
to myTableView
;
At first, there's no data in myModel
, I use the hideColumn(0)
to do the job, and it works well, while after I load data to myModel
, the column that I've hidden just shows up.
Would anyone tell me how to hold the hidden state of a column when the model changes?
Any suggestion is appreciated.
OK, here is the code.
void ModelView::createModelAndView()
{
_TableModel = new TableModel(this);
_Table = new QTableView(this);
_Table->setModel(_TableModel);
_Table->hideColumn(0);
_Table->hideColumn(10);
}
Now the _TableModel
has no data.
Then follows this:
_TableModel->loadData();
The loadData()
method is used to get data and push data to the model. Right after this step the view(i.e. _Table
) changes.
Upvotes: 4
Views: 4078
Reputation: 14603
Do this:
connect(dataModel, SIGNAL(modelReset()), SLOT(modelReset()));
in the modelReset()
slot:
void SomeClass::modelReset()
{
tableView->hideColumn(0);
}
Upvotes: 2
Reputation: 9853
First you set a data model, then tweak its GUI representation:
tableView->setModel(dataModel);
tableView->hideColumn(0);
Upvotes: 1