PDA

View Full Version : An old topic,custom list view



MorrisLiang
24th May 2010, 16:02
The default list view in QT is really too basic to satisfy me.And the delegate isn't enough.I want to fully custom it,just like rendering a custom widget in a list.Take twitter as an example.I have a timeline with 70 tweets.I want to show them in a fashion style.

Here's my few thoughts:
1.Subclass the QListView,override the paintEvent(),draw everything by myself.

2.Use Graphics View Framework.The 40000 chips demo really shows its power.I think managing only a list of tweet widgets would be a piece of cake to it.

3.I take use of the QScrollBar.Since the tweet widget will have a minimum size(say 40*100),So if the viewport's size is(160*100),then I can only see 5 widgets at most(3 of them will totally visible,while the other two will be seen partly).Then I create 5 widgets(instead of creating 70 widgets to save memory).Every time the user drag the scrollbar,I adjust these 5 widgets' content & position.
Also I have the 6th widget to calculate each of the 70 tweet widgets' actual size.Then I do some math and assign the value to the scollbar,so it knows the scrolling range.


I'm a newbie to Qt,so I don't know which one would be better.But obviously,the first one would suck.I hope you guys can tell me more about this.All the pros and cons.
This is not totally a question.And I think bring up a topic is better than just ask and answer.

tbscope
24th May 2010, 18:22
Well, the first suggestion would definitely not suck. If you have multiple views that need to be synchronized, then a subclass of QAbstractItemView is the best thing to do. Granted, this is very complex. Look at the Chart example on the Qt documentation website.

If you only want to show a list of items without linking the data to other widgets (think about updating each widget etc...) and you do not want to edit the items, then I personally think using QGraphicsView is a little bit easier.

The hardest part of subclassing an item view is not the painting but finding the rectangles and regions for items and selections. At least, I like to think so.

MorrisLiang
24th May 2010, 18:51
Well,I saw the Chart example.Unfortunately,the list view is still too simple.
Thanks your suggestion,I'll take a look at the QGraphicsView.