QProgressBar in QTreeWidget?
I have a QTreeWidget that displays information. It only has top level items, each having 5 fields. Right now, these 5 columns are all text (QString). The last one represents some kind of progress, so I'd like this to be a progress bar (QProgressBar).
The documentation of QTreeWidget says:
Quote:
void QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )
Sets the given widget to be displayed in the cell specified by the given item and column.
Note that the given widget's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the tree widget item.
This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView and subclass QItemDelegate instead.
This function was introduced in Qt 4.1.
See also itemWidget() and Delegate Classes.
So, supposedly I can set any widget for any cell. But I'm unsure of what is meant with
Quote:
This function should only be used to display static content in the place of a tree widget item.
A progress bar is not static, so it's implied I cannot use it. Or does "static" refer to the fact that it should remain the same widget one it's set?
Or should I use QAbstractItemModel with QTreeView instead? (I have tried this approach briefly, but with no success so far. I'd like to use the QTreeWidget, because it's easier to use, rather that putting many hours in the abstract model.)
Re: QProgressBar in QTreeWidget?
why you can't write your own delegate with progress bar?
Re: QProgressBar in QTreeWidget?
How do you mean?
I'm not very familiar with the MVC idea, and I was hoping to get by the easy way ;)
I tried to just use QTreeWidget::setItemWidget() and it seems to work just fine. I was just wondering if this is a good approach, or that I'm doing it all wrong...
Re: QProgressBar in QTreeWidget?
simple delegate example
Code:
{
bar->setMaximum(100);
bar->setValue(50);
return bar;
}
{
editor->setGeometry(option.rect);
}
in widget:
Code:
...
tw->setItemDelegate(new MyItemDelegate);
...
Re: QProgressBar in QTreeWidget?
Please search the forums:
Re: QProgressBar in QTreeWidget?
Quote:
Originally Posted by
jpn
Please search the forums:
Thank you for pointing me there. Your example in that thread is extremely useful!
I'm not sure whether I forgot to search or used the wrong terms, but I definitely need to sleep more ;)