161 {
162 QStyleOptionViewItem options = option;
163 initStyleOption(&options, index);
164 painter->save();
165
166 const auto shortcutString = index.data().toString();
167
168
169 if (option.state & QStyle::State_Selected) {
170 painter->fillRect(option.rect, option.palette.highlight());
171 } else {
172 painter->fillRect(option.rect, option.palette.base());
173 }
174
175 options.text = QString();
176 options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter, options.widget);
177
178 if (!shortcutString.isEmpty()) {
179
181 const auto list = [&shortcutString] {
182 auto list = shortcutString.split(QLatin1Char('+'), Qt::SkipEmptyParts);
183 if (shortcutString.endsWith(QLatin1String("+"))) {
184 list.append(QStringLiteral("+"));
185 }
186 return list;
187 }();
188 btns.reserve(list.size());
189 for (const QString &text : list) {
190 QRect
r = option.fontMetrics.boundingRect(text);
191 r.setWidth(
r.width() + 8);
192 btns.append({
r, text});
193 }
194
195 const auto plusRect = option.fontMetrics.boundingRect(QLatin1Char('+'));
196
197
198 int x = option.rect.x();
199 const int y = option.rect.y();
200 const int plusY = option.rect.y() + plusRect.height() / 2;
201 const int total = btns.size();
202
203
204 painter->translate(QPoint(0, (option.rect.height() - btns.at(0).first.height()) / 2));
205
206 int i = 0;
207 painter->setRenderHint(QPainter::Antialiasing);
208 for (const auto &btn : btns) {
209 painter->setPen(Qt::NoPen);
210 const QRect &
rect = btn.first;
211
212 QRect buttonRect(x, y,
rect.width(),
rect.height());
213
214
215 auto shadowRect = buttonRect.translated(0, 1);
216 painter->setBrush(option.palette.shadow());
217 painter->drawRoundedRect(shadowRect, 3, 3);
218
219
220 painter->setBrush(option.palette.button());
221 painter->drawRoundedRect(buttonRect, 3, 3);
222
223
224 painter->setPen(option.palette.buttonText().color());
225 painter->drawText(buttonRect, Qt::AlignCenter, btn.second);
226
227
228 if (i + 1 < total) {
229 x +=
rect.width() + 5;
230 painter->drawText(QPoint(x, plusY + (
rect.height() / 2)), QString(
"+"));
231 x += plusRect.width() + 5;
232 }
233 i++;
234 }
235 }
236
237 painter->restore();
238 }