This isn't easy but I think I can help. You need to create a delegate where you will have also a reference of your model (and a proxy if you have one).
Here is what I've made for my music player. Note that I used QStyledItemDelegate and not QAbstractItemDelegate:
void YourItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStandardItem *item = _model->itemFromIndex(_proxy->mapToSource(index));
switch (item->type()) {
case Miam::IT_Album:
this->paintRect(painter, o);
this->drawAlbum(painter, o, static_cast<AlbumItem*>(item));
break;
case Miam::IT_Artist:
this->paintRect(painter, o);
this->drawArtist(painter, o, static_cast<ArtistItem*>(item));
break;
case Miam::IT_Disc:
this->paintRect(painter, o);
this->drawDisc(painter, o, static_cast<DiscItem*>(item));
break;
case Miam::IT_Separator:
this->drawLetter(painter, o, static_cast<SeparatorItem*>(item));
break;
case Miam::IT_Track: {
/// etc
break;
}
default:
QStyledItemDelegate::paint(painter, o, index);
break;
}
}
Then, in the QTreeView class you have:
bool QTreeView::isExpanded(const QModelIndex & index) const
You can check if your item is expanded or not to do some special painting operations.
With some hard work, you can achieve something like this:
