For days I’ve been battling with QT, Models, Views, Delegates. I wish to know that architecturally, I am on the right Track. If you can comment on that, you’re more than welcome.
GOAL:
A Scrollable Buddy List, similar to what Skype has. The following requirements must be supported:
-
complete control over the drawing
of a row. Typically, Icons of
variable width based on status of
the object represented by the row. -
Variable height for rows,
typically, more detailed row display
for the selected row. - Added controls for selected rows (action
buttons). - Full control over the
sorting of the list - different
types of rows typically, a buddy or
a textual placeholder with a label
indicating the type of buddies
directly under it (e.g. “offline
contacts”, “online contacts”).
My thoughts were as follows:
- Use a QListView for the listview control
Use a derived QAbstractList model to hold the buddy data. It will have an std::vector array with a collection of “MyContactClass”. Each “MyContactClass” instance will represent a buddy, with its related data fields - Use a QAbstractItemDelegate derived class to handle the painting and sizeHinting of the rows
- Hook up the model and delegate to the QListView
- populate the model…
- Have the QListView populated
I understand there are many details to this and it’s not trivial at all. What I wanted to ask you is: Are items #1 to #6 correct architecturally given what I’m trying to do.
I have done a lot of model/view programming in Qt. Your method seems correct to me.
You might have a tricky time adding these action buttons to the delegate. QAbstractItemDelegate doesn’t play very nice with custom widgets but does well with style option controls.
And of course you will need to register your MyContactsClass with the MOC so that it can be used in QVariant.
Other than that, looks good.