Я использовал QStyledItemDelegate, чтобы добиться этого, и это функция рисования
void PixelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option , const QModelIndex &index) const
{
int offset = 0;
int offsetIcon = 0;
const QAbstractItemModel *model = index.model();
const TreeModel *myModel = (TreeModel*)(model);
TreeItem* item = myModel->getItem(index);
Container* cont = item->GetContainer();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(Qt::NoPen);
painter->translate(option.rect.x(), option.rect.y());
painter->scale(.4, .4);
if (option.state & QStyle::State_Selected)
painter->setBrush(option.palette.highlightedText());
else
painter->setBrush(option.palette.text());
if (cont->GetGeometry()->GetType() != "NO_TYPE")
{
QString qstrIconName = cont->GetGeometry()->GetType().c_str();
QString qstrIconPath = QCoreApplication::applicationDirPath();
QPixmap pixmap;
qstrIconPath = qstrIconPath + "/Icons/" + qstrIconName + ".png";
pixmap.load(qstrIconPath);
QImage image = pixmap.toImage();
painter->drawImage(0, 6, image);
offset += 20;
offsetIcon += 50;
}
if (cont->getNumberOfFunctions() > 0)
{
QString qstrIconName = "FUNCTION";
QString qstrIconPath = QCoreApplication::applicationDirPath();
QPixmap pixmap;
qstrIconPath = qstrIconPath + "/Icons/" + qstrIconName + ".png";
pixmap.load(qstrIconPath);
QImage image = pixmap.toImage();
painter->drawImage(offsetIcon, 6, image);
offset += 20;
offsetIcon += 50;
}
if (cont->GetNumberOfAnimationChannels() > 0)
{
QString qstrIconName = "ANIMATION";
QString qstrIconPath = QCoreApplication::applicationDirPath();
QPixmap pixmap;
qstrIconPath = qstrIconPath + "/Icons/" + qstrIconName + ".png";
pixmap.load(qstrIconPath);
QImage image = pixmap.toImage();
painter->drawImage(offsetIcon, 6, image);
offset += 20;
}
painter->restore();
QStyleOptionViewItem newoption = option;
newoption.rect.setX(option.rect.x() + offset + 3);
newoption.rect.setY(option.rect.y());
QStyledItemDelegate::paint(painter, newoption, index);
}