I have created by myself model (MyListModel) that store list of my objects MyObj. MyObj stores some text information. Then I created class ItemDelegate, in order to manage view of every item and also to add QProgressBar to each item. The problem is that I need busy progressbar, but when I execute app, QProgressBar doesn't do any action.
I'm guessing, it's because QListView only show static data. Is there any way to make it work properly? My realisation of paint method for Delegate:
void StatusItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
StatusItem my_item = index.data().value<StatusItem>();
wdg->name->setText(my_item.m_name);
switch (my_item.m_state)
{
case 0: wdg->progress->setMaximum(0); wdg->progress->setMinimum(0); break;
case 1: wdg->progress->setRange(0, 0); wdg->progress->setValue(100); break;
case 2: wdg->progress->setHidden(true); break;
}
QPalette pal;
QLinearGradient gradient(0, 0, 0, 100);
if ((option.state & QStyle::State_Selected) == QStyle::State_Selected)
{
pal.setBrush(QPalette::Window, QBrush(QColor(0, 255, 200)));
}
else
{
gradient.setColorAt(0.0, QColor(255,250,0));
gradient.setColorAt(1.0, QColor(255,255,255));
pal.setBrush(QPalette::Window, QBrush(QColor(Qt::transparent)));
pal.setBrush(QPalette::Window, QBrush(gradient));
}
wdg->setPalette(pal);
wdg->resize(option.rect.size());
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->translate(option.rect.topLeft());
wdg->render(painter);
painter->restore();
}