PDA

View Full Version : QTableView that display individual items



Zalwou06
11th May 2012, 12:14
hi all

First thanks to the community that always provide great help.

I have a big problem using my QTableView while sorting.
My table view is used to display a list of contacts, so they are individual items. I need to display those contacts in list mode and tile mode.

I have all my contacts in a QObjectList, then I create a QAbstractTableModel that use this list as the model data and a QAbstractItemDelegate that paint the data.
I need to sort the table view as well so I have created a QSortFilterProxyModel and set it to the table view.

Then I call proxy->sort(0, ascending/descending) and my table is updated.

Everything works fine in list mode, my model returns rowCount = the number of contacts and columnCount= 1.

But there is a big problem while I want to display my items in tile mode, my model returns rowCount = ceil((float)number of contacts / 3); and columnCount= 3 then on the first columns contacts are well sorted but on other columns this is a mess, nothing is sorted correctly and I even have blank tile (or cell) in the middle of the table view.

The same problem occurs while filtering the contact with the proxy.

So My question is how can do that ? I even think that I can't do it with a table view because it needs to have the same data for a single row and display the data informations in the different columns.

If I can't use a QTableView do I have to create a special widget with scrolling and put all my contacts in it ? Doing this make me sick because I have to implement clicks, sorts and filters by hand.

Thanks for you reply anyway.

Zal

Spitfire
14th May 2012, 16:38
Why you won't use list view which has list/icon view already implemented?

No point reinventing the wheel.

Zalwou06
15th May 2012, 12:58
Hi

Do you talk about QListView ?

Spitfire
15th May 2012, 13:07
QListView (http://qt-project.org/doc/qt-4.8/QListView.html) + setViewMode( QListView::IconMode ) (http://qt-project.org/doc/qt-4.8/qlistview.html#viewMode-prop).

Zalwou06
15th May 2012, 13:19
OMG ;)

thanks a lot, I was stuck with the table view and I never had a look to that class.

Thank you so much