PDA

View Full Version : Clear QTableView of Hidden columns



mechsin
29th August 2012, 21:06
I have an excel like spread sheet that I am showing some test date in and I am using a QTableView in conjunction with a model. The user is allowed to both hide and move columns of the data. I want to be able to load data from a file. Everything works fine except the TableView seems to be holding onto which columns were hidden even after the model is reset.

My model has a changeDataSet function that is like this


def changeDataSet(self, dataset)

self.beginResetModel()
self.dataset = dataset
self.endResetModel()



This works fine the right number of columns and rows show up. All the data is in the right spot but the hidden columns seem to persist. Is there any way to reset the QTableView or do I need to go through and unhide all the hidden columns before I invalidate the model. If you couldn't tell from the Code block I am using PyQt and my data is coming from a Pickle file which is how I have a entire dataset class to just plug back in.

ChrisW67
31st August 2012, 00:48
Just iterate over the columns of the new model and showColumn() the columns in a slot attached to the modelReset() signal.

mechsin
31st August 2012, 13:32
Yeah that is the solution I came to as well in fact I already had a function in the view for unhiding all the columns. Although connecting to the modelReset signal I hadn't thought of. It just seemed like there should have been a more inclusive solution like a reset function or something. Additionally I was just concerned that there may be other things in the view that might not be resetting properly and that I just haven't noticed them yet.

ChrisW67
1st September 2012, 03:49
Changing data in the model should not automatically change the state of the view. The view has no idea of the meaning of the data in the model or how that might have changed. In most cases you do not change the entire meaning of the underlying model only its content. I think it would be downright annoying if, every time you caused a QSqlQueryModel to requery a growing table, the view reordered, unhid and unsorted rows/columns when it is the same data being presented.