How to display rich text in table view?
Printable View
How to display rich text in table view?
you can try this, a little bit tricky, but works :)
Code:
{ m_label->setTextFormat(Qt::RichText); } MyItemDelegate::~MultistringsItemDelegate() { delete m_label; m_label = 0; } QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(option); Q_UNUSED(index); } void MyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if (!lineEdit) return; model->setData(index, lineEdit->text()); model->setData(index, QString("<span style=\" color:#0ff000;\">%1</span>").arg(lineEdit->text()), Qt::DisplayRole); } void MyItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const { m_label->setText(text); m_label->setPalette(pal); m_label->resize(option.rect.size()); painter->drawPixmap(option.rect, p); }
Or you can take a look at the "similar threads" table on the bottom of the thread page.
thank u so much guys!
you can also make like this
Code:
... void MyItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const { Q_UNUSED(rect); QTextDocument doc; doc.setHtml(text); doc.drawContents(painter, option.rect); } ...