I'm making a form for QBE with text completion (as for now it will only be a prefix search).
I have a data model inheriting from QAbstractTableModel with (actually not yet, but will be) relational data in it. And I want to give the user possibility to write only the beginnings of name, surename, city, order number etc. and then to auto-complete the rest of fields.
As this is the first time I'm trying to write something in Qt after some looking around the classes I thought that QTableView will be something I should go for, so I tried QItemDelegate to create persistent aditors in a nice grid. And there problems began:
- as I mentioned in the first post I couldn't get to keep the selection as I wanted
- when I set the input of fields it generated filter on data which returned 0 rows and I couldn't traverse through all fields with tab anymore
- also there was problem as I couldn't leave the grid using tab (it cycles through all cells on the grid, but does not leave the table widget)
So after some thinking and looking at my code I thought that I wrote much more code (handling data change in model, creating and monitoring editors) to force QTableView to act as I want then use the features of QTableView.
So I switched to QTableWidget. I just set it to have one row and never change it (this solves problem with 0 rows in data model). Set widgets of all cells to class inheriting from QLineEdit and wrote code to take care of data changes in data model.
And that solved my problem with "dissappearing" selection. It seems like QTableView does something more than just call QItemDelegate::setEditorData() when data in the model is changed.
Also the problem with the tab traversal inside the table was solved with this change.
And only thing I see now that I have to deal with is making the tab traversal not getting stuck inside the QTableWidget.
Bookmarks