PDA

View Full Version : List display options, QListView, QListWidget, QStyledItemDelegate....



dubstar_04
18th February 2010, 21:42
Hi Guys,

I am pretty new to programming and I am starting to learn C++ and QT.

As a little project to get me going I am writing a little Twitter application.

My problem is that I want to have a List with with the users icon, name and status listed.

I have implemented this using a QListWidget and adding QListWidgetItems using a QWidget with the information laid out (see attachment).

This seems a pretty ugly way to implement what should be a simple feature and is causing real problem when implementing reply and open link features when the user clicks the list item.

I have read the documentation, googled and searched this forum and I am a bit dizzied by all the information.

What i think I need to do is subclass QStyledItemDelegate to draw the information and react to the users click.

Please could you suggest the best way to implement this?

Should I use a subclassed tree model and draw the information from there and on users click pass the model index to the next function?

Any help will be very appreciated!!

Thanks,

Dubstar_04

http://lh6.ggpht.com/_yGkw0Cr-R9E/S32xh2H5LII/AAAAAAAAB7Y/xpI3ppQUkSg/s512/Twiti5h.jpeg

psih128
19th February 2010, 07:50
The QAbstractItemModel classes do not allow you to draw anything special, but they do simplify things A LOT when it comes to tree/list manipulations. So you could implement a QAbstractListModel for you application, since you need a list. Then you could implement a QAbstractItemDelegate to present the records in the list with custom widgets.

Read mode about model/view framework, and about delegation of item representation via custom widgets. There are plenty examples to cover this in Qt.

dubstar_04
19th February 2010, 12:58
Thanks for your reply.

I have read all the documentation over and over, so much that i am actually confused over how to impliment the features and functions I want.

You think I should use:

A Subclassed QAbstractListModel to hold the, QIcon, and 2 QStrings,
Then Subclass QStyledItemDelegate or QAbstractItemDelegate to draw the listitems to a QListView and react to user clicks?

The example I showed in the picture uses custom QWidgets to impletement the required functions but this seems a very heavy way to retrieve information,

1. Pass item index to a function
2. retrieve the widget name from the item index
3. findchild <QLabel * >"twitterName" or "Status";
4. retrieve the text from the label and pass it to a processing function to parse the urls and return them with the users name.

So if the data is stored in a model i should be able to used QStyledItemDelegate to retrieve the data using the item index?

Are there any performance issues / benefits with any particular method of implimentation?

Thanks,

Dubstar_04