void delegate::paint(QPainter* painter,const QStyleOptionViewItem& option,const QModelIndex& index )const{ painter->save(); if (option.state & QStyle::State_Selected) drawBackground(painter, option, index); QTextDocument* doc=new QTextDocument(); QString str="<html><body><p><font face=\"Symbol\">t</font><font face=\"Tahoma\">d</font></p></body></html>"; doc->setUndoRedoEnabled(false); doc->setHtml(str); doc->setTextWidth(option.rect.width()); doc->setUseDesignMetrics(true); doc->setDefaultTextOption (QTextOption(Qt::AlignHCenter)); doc->setDefaultFont(QFont("Tahoma",13,QFont::Bold)); drawDisplay(painter, option, option.rect,""); painter->translate(option.rect.topLeft()); doc->drawContents(painter,QRectF()); painter->restore();}
QPalette YouPalette; // YouPalette.setColor..... и т.д, какая палитра тебе нужна такую и задаешь QAbstractTextDocumentLayout::PaintContext ctx; ctx.palette = YouPalette; ctx.clip = option.rect; doc->documentLayout()->draw(&painter, ctx);
ctx.clip = option.rect;
QTextDocument doc; doc.setHtml(index.data(Qt::UserRole + 1).toString()); doc.setTextWidth(option.rect.width() - 40); QPixmap pix(doc.size().toSize()); pix.fill(Qt::transparent); QPainter p(&pix); p.setPen(Qt::NoPen); QAbstractTextDocumentLayout::PaintContext ctx; ctx.palette = myPalette; QRect r = pix.rect(); if (r.isValid()) { p.setClipRect(r); ctx.clip = r; } doc.documentLayout()->draw(&p, ctx); painter->drawPixmap(option.rect.x() + 20, option.rect.y(), pix);