View Full Version : overriding QListWidget advice

27th September 2010, 23:45
I would like to implement a cylinder like list. For that purpose I override QListWidget.

The way it works is: after items added (number of items must be bigger then the number of items that could be displayed in viewport) and call show() widget creates extra items (function is called in resize event), that way you get a fill of infinitum loop. Selected item is alway in the center of widget.

Viewport: 5 items
List: 10 items
Extra items: 3 at start (last 3 of the list) and 3 at the end (first 3 of the list)
When selected item is 10 item of the list, next selected item is first item of the list.

I haven't figured out how to handle the situation where there are less intems than the item that could be displayed in viewport. The consequence of that problem is after calling clear() how to handle adding items.

the only idea i have is create a list with empty items and while adding an item remove empty one.

Any advice?

PS: hope my English is understandable.

28th September 2010, 00:12
QListWidget is not well suited for such a situation. Implementing a custom widget (based on QFrame or QAbstractScrollArea) would be a better approach, in my opinion. If you start manipulating items like you are doing it now, the scrollbar value will make no sense and in border situations (like the one you mention) there will be no viable solution. With a custom widget you could overcome the weaknesses. It's only a matter of deciding how much functionality of QListWidget you really need.

28th September 2010, 22:51
functionality i need from QListWidget are:
- container
- selection (user events and in code)

That's why I find QListWidget useful. I'll do a research about your advice.

28th September 2010, 23:39
If all you want is to show a bunch of items with ability to select a subset of them then forget about QListWidget and implement something simpler.