PDA

View Full Version : tableview model view problem



skuda
1st December 2007, 17:54
Hello, i am using two tableviews with qsqlquerymodel, in the first table i show the invoice headers and in the second the lines of every invoice (when i select the invoice in the first table with the mouse), i have any comboboxes and lineedit to filters the invoice headers, the problem i have is that when i use any of the invoice header filter i would like that the invoice lines table was cleared but if i use the .clear() method in the model i lose the header names setted with .setHeaderData, i have tried too setting and invalid qsqlquery with .setquery() but when i reload any invoice lines the columns lost his size, altough i am using tableview.resizeColumnsToContents() after every setquery in this table, i have tried too reset the tableview and headers but this doesnt works either so the only solution that i think i could use subclass qsqlquerymodel and reimplement headerdata function but i would like to avoid subclass qsqlquerymodel if possible, anyone has a better solution? Thanks.

skuda
3rd December 2007, 13:09
any good idea on this?

wysota
3rd December 2007, 13:12
Why do you want to clear the model? I can't follow your concept... are you deleting something? Could you show a mockup image of what you do?

skuda
3rd December 2007, 13:41
here you can view a photo of the dialog, the table below is the lines of the document selected in the table above (headers and lines of tickets or invoices), the comboboxes and lineedit right to table are the filters of the above table when i apply a filter i would like to clean the table below (because the selected document it is loss) but i cant find any good way to do it, like i explain in first post.

wysota
3rd December 2007, 13:57
So you could say that the bottom table show "children" of the item selected in the upper table?

If so, then why not make a proper hierarchical model with parents and children. Then populating the bottom table would be as simple as setting the root index to the index of the item selected in the upper table.

Regardless of your decision, the headers could be changed by using a proxy model over the sqlquery (or your custom) model. You could also subclass QSqlQueryModel and return proper column names regardless of whether the resulting set contains any rows or not. Then clear() wouldn't remove your headers.

skuda
3rd December 2007, 15:02
i think i will subclass qsqlquerymodel and reimplement headerdata, because it is much less work than do a proper sql model with parent and children