Hello,
I tried a bit and I found the solution
class NoTintIconDelegate : public QStyledItemDelegate {
public:
explicit NoTintIconDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override {
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
// Prepare the painter
painter->save();
// Draw the background and selection
if (opt.state & QStyle::State_Selected) {
painter->fillRect(opt.rect, QColor("#4d78cc"));
painter->setPen(opt.palette.highlightedText().color());
} else {
painter->fillRect(opt.rect, QColor("#21252b"));
painter->setPen(opt.palette.text().color());
}
// Draw the text
QString text = index.data(Qt::DisplayRole).toString();
QRect textRect = opt.rect.adjusted(20, 0, 0, 0); // Adjust for icon space
painter->drawText(textRect, Qt::AlignVCenter | Qt::TextSingleLine, text);
// Draw the icon manually without tinting
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
if (!icon.isNull()) {
QPixmap pixmap = icon.pixmap(opt.decorationSize);
painter->drawPixmap(opt.rect.left() + 2, opt.rect.top() + (opt.rect.height() - opt.decorationSize.height()) / 2, pixmap);
}
painter->restore();
}
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override {
QSize size = QStyledItemDelegate::sizeHint(option, index);
size.setWidth(size.width() + 20); // Add space for icon
return size;
}
};
and then :
treeView->setItemDelegate(new NoTintIconDelegate(this));
Have a nice day !