hlp:桂林国际齿轮泵代码
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#include "HtmlDelegate.h"
|
||||
|
||||
HtmlDelegate::HtmlDelegate(QObject *parent) : QAbstractItemDelegate(parent){}
|
||||
|
||||
//HtmlDelegate::HtmlDelegate(QObject *parent = nullptr) : QAbstractItemDelegate(parent) {}
|
||||
|
||||
|
||||
void HtmlDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
QString html = index.model()->data(index, Qt::DisplayRole).toString();
|
||||
QTextDocument doc;
|
||||
doc.setHtml(html);
|
||||
doc.setTextWidth(option.rect.width());
|
||||
|
||||
painter->save();
|
||||
painter->setClipRect(option.rect);
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
// 绘制选中项的背景颜色
|
||||
painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
|
||||
}
|
||||
|
||||
painter->translate(option.rect.topLeft());
|
||||
doc.drawContents(painter, QRectF(QPointF(0, 0), QSizeF(option.rect.size())));
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize HtmlDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
QString html = index.model()->data(index, Qt::DisplayRole).toString();
|
||||
QTextDocument doc;
|
||||
doc.setHtml(html);
|
||||
doc.setTextWidth(option.rect.width());
|
||||
return QSize(doc.idealWidth(), doc.size().height());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user