PDA

View Full Version : GroupListView in Qt?



AyaKoshigaya
27th March 2012, 15:12
Hi,

is it possible to do something similar to this in Qt?
http://objectlistview.sourceforge.net/python/groupListView.html#using-grouplistview

Cheers,
Aya

Lykurg
27th March 2012, 15:56
Yes. Next time please open the documentation and search a little bit and/or post such questions in the newbie section. (moved!)

See QTreeView or QTreeWidget.

AyaKoshigaya
27th March 2012, 16:03
I don't see how I can do this with QTreeView/QTreeWidget by default - have you looked at the website link I posted??

How can I do this grouping with QTreeView/QTreeWidget?

Lykurg
27th March 2012, 16:25
have you looked at the website link I posted??Yes, but have you read the documentation to QTreeView? Isn't the image https://qt-project.org/doc/qt-4.8/images/macintosh-treeview.png almost what you want? The grouping must be indeed be done by the model or you, when using QTreeWidget.

wysota
27th March 2012, 16:31
I don't see how I can do this with QTreeView/QTreeWidget by default - have you looked at the website link I posted??

How can I do this grouping with QTreeView/QTreeWidget?

The only difference I can see is the space betweeen top-level items. Subclassing QTreeView and reimplementing visualRect() should be enough to obtain that.

AyaKoshigaya
27th March 2012, 16:39
Hi,

the GroupListView on the website is more than just a simple QTreeWidget/View..
The big difference is the grouping (in the example the rows with blue background) - Sure, I can do this by simply add an QTreeWidgetItem (or via a Model for QTreeView), but the text of the group-row can be longer than the cell it is in.

So what I need (if I have to do the grouping myself) is the ability to have a row that ignores the column boundaries.
I am not sure how I should describe it, in html it would be <td colspan="5">...

Aya

Lykurg
27th March 2012, 17:00
As told, reading the documentation could help: QTreeView::setFirstColumnSpanned(). And the styling of the items can be easily done with a proper delegate. You might also want to read about model & view architecture in Qt.

AyaKoshigaya
27th March 2012, 17:07
Thanks a lot, setFirstColumnSpanned() was very helpfull.

Aya

PS: Next time I will read trough the whole documentation before asking a question in this forum.. seems as if I got the idea of this forum wrong.

wysota
27th March 2012, 17:08
the GroupListView on the website is more than just a simple QTreeWidget/View..
No, it's not. Even the webpage you gave us a link to says that. It claims that sometimes you need something more than a flat list, that you need to have groups of items. (Un)Suprisingly that's exactly what a tree view does.