> > 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).
>
> Right. That might make things more difficult. It suddenly
> occurred to me that you could use QListWidget for your view
> and call setItemWidget() for each item, but you may encounter
> problems depending on how many widgets you have and how
> dynamic they are:
>
> http://doc.trolltech.com/4.4/qlistwidget.html#setItemWidget
Thanks, I'll look in to that tomorrow. It says however 'This function
should only be used to display static content', would that be a problem
with e.g. the progressbar?
> It's interesting that you are using QWidget::render() to draw
> widgets in delegates because the "classic" way to do this is
> to render certain kinds of controls using the QStyle API.
I simply thought: I need to 'paint' my mWidget now, went to the QWidget
docs and found no 'paint' functions, but there was a 'render' function.
> Here's some code
> snippets for a progress delegate I wrote some time ago -
> hastily converted to C++ for your benefit:
>
> void ProgressDelegate::paint(QPainter *painter,
> const QStyleOptionViewItem & option, const QModelIndex & index) {
> QVariant value = index.data(Qt::UserRole);
> bool ok = false;
> double percentage = value.toDouble(&ok);
> QStylePainter stylePainter;
> stylePainter.begin(painter->device(), parent());
> QStyleOptionProgressBarV2 progressOption;
> progressOption.initFrom(parent());
> progressOption.rect = option.rect;
> progressOption.minimum = 0;
> progressOption.maximum = 100;
> progressOption.progress = int(percentage);
> progressOption.text = index.data(Qt::DisplayRole).toString();
> progressOption.textAlignment = Qt::AlignCenter;
> progressOption.textVisible = true;
>
> stylePainter.drawControl(QStyle::CE_ProgressBar, progressOption);
> stylePainter.end();
> }
>
> I've removed lots of code, so that's just a basic sketch. You
> should see
> http://www.qt-apps.org/content/show.php/?content=52389 for
> some context.
>
> I hope that helps show you how the QStyle API can be used to
> "draw widgets", though I realise that some experimentation
> may be necessary to get the desired look and feel.
I didn't realize you could just use a different painter. Is there any
way to pass a 'compound' widget like myWidget to some painter and have
it draw the subwidgets that need it in the correct ('current' or
'parent') style?
Arnt
_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback