> On Friday 12 December 2008, Witteveen, Arnt wrote:
> > 
> > Hi, I'm looking to implement something like firefox's list of
downloaded
> > items: a scrollable list (mine will also allow rearaanging 
> > by drag and drop) of items, where the items are a little more than
an icon and 
> > some text (e.g., a big icon, a few lines of text, a link you can
click 
> > and maybe even a button).
>
> The recommended way to do any extensive customization of 
> items is to create a custom delegate and set it on a 
> QListView widget. For simple datasets, you could use a 
> QStandardItemModel object to hold the information about the items.
> 
> See "An Introduction to Model/View Programming" to get started:
> 
>   http://doc.trolltech.com/4.4/model-view-introduction.html
> 
> David Boddie


Hi, thanks for that hint, I completely missed that bit somehow at first.
However, implementing a paint function that draws the contents of a
normal QWidget is not as simple as I imagined. And after I get painting
to work, I'd like the widgets to actually *work* as well (I'm looking
for a progress bar, text and a web link and some icons).

I currently have this (as a test, just draw the same 2 widgets for each
item) put in a QListView:

GTestDelegate::GTestDelegate()
{
    mWidget = new QWidget();
    QHBoxLayout* theLayout = new QHBoxLayout(mWidget);
    theLayout->addWidget( new QLabel(tr("a")));
    theLayout->addWidget( new QLabel(tr("b")));
    mWidget->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
    mWidget->adjustSize();
}

void
GTestDelegate::paint( QPainter *painter, 
                      const QStyleOptionViewItem &option,
                      const QModelIndex &index) const
{
    mWidget->render(painter, QPoint(), option.rect);
}

This draws only one line (all on top of eachother?). I'm guessing the
widget render call expects targetOffset and sourceRegion to contain
certain values, but the docs here
http://doc.trolltech.com/4.4/qwidget.html#render-2 don't say anything on
what they expect in these parameters. I'm trying to guess them, but I
don't understand why you would have a separate offset and a drawing
rectangle. The offset info, if it means what I'm guessing it does, an
offset from some base point, could just as well be in the rectangle, I
would think? It seems to be in the rectangle I get in the 'option'
parameter.


So, even after I get this to work (with some help from this list, I
hope!) a feature request: why can't I draw an item by using QT widgets
out of the box (like I could do for editors, if I read the examples
correctly)? I'm clearly not the first to do this, see
http://lists.trolltech.com/qt-interest/2006-12/thread00210-0.html . That
thread hints at too many widgets, but since only so may can be on screen
due to screen size, I don't really see the problem. And I'm not quite
sure what the conclusion of that thread was. The attachment to the last
messge doesn't download.

Arnt

_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback

Reply via email to