[Qt-interest] ISO Model/View Solution for scrolling list of widgets

Andre Somers andre at familiesomers.nl
Thu Oct 29 09:02:22 CET 2009


KC Jones wrote:
> I'm struggling with an implementation problem that I hope someone here
> can help me with.
>
> I have an application that needs to implement something like the
> FireFox Downloads window.  Behind this is a model that describes the
> items with various strings, files paths, progress data.  The number of
> items and their data vary in real time, all captured in a
> QSqlTabelModel.  Through this UI I need to provide controls very
> similar to the stop/start/cancel controls on the FF download window.
>
> Using QListView + QStyledItemDelegate + custom editor widget seems
> natural.  I have this sketched in.  (QTreeView is out since the custom
> widget cannot live with a simple column oriented layout.)  The
> selected/edited item represented by my custom editor widget looks
> good.  My problem is that every item in the list really wants to be an
> instance of that widget.  Selected or not, I want every item to
> display the same data in the same way.  I could live with requiring
> the user to select an item for the "editor" widget to be enabled.  But
> I want all rows to use the same custom widget definition to display
> itself.
>
> So is there a way in QStyledItemDelegate::paint() to leverage my
> custom widget's paint impelementation directly?  Or else make use of
> the custom widget's layout to at least simplify my paint() method?
> I've also looked at writing my own ScrollingWidgetList widget derived
> from QScrollArea, but that seems like a major project.  I'm hoping
> there are simpler solutions.
>
> This seems like a fairly generic problem.  If this is in some docs or
> tutorials or samples, please clue me in.
>
>   
Yes, it is a generic problem. But it is not all that easy to solve.
In Qt Labs, there is a project called ItemViewsNG. It is a new take on 
the whole ItemView idea, and it has the potential to make this kind of 
thing much easier. Perhaps it already does what you need; I have not 
personally tried it recently but I have seen the presentation on the Qt 
Developers Days and talked with the developer a bit.
Another approach you can use (and this is what I currently do) is to 
leverage the work that has been done by KDE on this. KDE developed this 
under the name Goya, and it is now known as KWidgetItemDelegate. It 
makes it possible to use widgets in your item views. It is not perfect, 
but it works. You can find the code in the KDE repository. Note it is 
licenced as LGPL.

See 
http://techbase.kde.org/Development/Tutorials/Introduction_to_Goya_usage 
for some information on how to use it, next to the API docs 
http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKWidgetItemDelegate.html

André





More information about the Qt-interest-old mailing list