QSqlTableModel change underling structure
I have a model that connects to a single table, this table will change the number of columns depending on certain conditions during the execution of the program. The model is connected to a QTableView.
I have a function that controls the number of columns at the end of the function i have a call to model->select(), to update the information of the model and tableView->reset(), to what i thought would rearrange the view adding or taking away columns.
The problem is that the view does not change from the original number of columns that it had. If i reduce the number i can see that the data change and show empty on the missing columns. Is there a command for the tableView to resize it self?
What kind of conditions ?
What does exactly change ?
The number of columns in the underling table changes. This is the sequence.
1- in the constructor a SQLTablemodel is created over a table that has 5 columns.
2-In the same constructor the model is displayed on a tableview. You can see all 5 columns.
3-The underling table is changed to 3 columns, or to 7 columns.
4. On the first case, the tableview shows data on the first 3 columns and the name of the old columns in column 4 and 5. On the second case the tableview still shows only 5 columns, with the new data.
How are you changing the underlying table ?
artwaw last edited by
@Dan3460 Hi, I had similar problems and solved them by manipulating associated QHeaderView (methods showColumn() and hideColumn()).
@artwaw yes that is the way i solved the problem. I setup a set number of columns and i hide and unhide columns. Thanks