84 {
85 QStyleOptionViewItem options = option;
86 initStyleOption(&options, index);
87
88 QTextDocument doc;
89
90 const auto original = index.data().toString();
91
92 const auto strs = index.data().toString().split(QLatin1Char(':'));
93 QString str = strs.at(1);
94 const QString nameColor = option.palette.color(QPalette::Link).name();
96
97 const QString component = QString("<span style=\"color: %1;\"><b>").arg(nameColor) + strs.at(0) + QString(":</b> </span>");
98
99 doc.setHtml(component + str);
100 doc.setDocumentMargin(2);
101
102 painter->save();
103
104
105 if (option.state & QStyle::State_Selected) {
106 painter->fillRect(option.rect, option.palette.highlight());
107 } else {
108 painter->fillRect(option.rect, option.palette.base());
109 }
110
111 options.text = QString();
112 options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter, options.widget);
113
114
115
116
117
118 const bool rtl = original.isRightToLeft();
119 if (rtl) {
120 auto r = options.widget->style()->subElementRect(QStyle::SE_ItemViewItemText, &options, options.widget);
121 auto hasIcon = index.data(Qt::DecorationRole).value<QIcon>().isNull();
122 if (hasIcon) {
123 doc.setTextWidth(
r.width() - 25);
124 } else {
125 doc.setTextWidth(
r.width());
126 }
127 }
128
129
130 painter->translate(option.rect.x(), option.rect.y());
131
132
133 if (!rtl) {
134 painter->translate(25, 0);
135 }
136
137 doc.drawContents(painter);
138
139 painter->restore();
140 }
static Q_DECL_UNUSED QString to_fuzzy_matched_display_string(const QString pattern, QString &str, const QString &htmlTag, const QString &htmlTagClose)
get string for display in treeview / listview. This should be used from style delegate....