+ ///
+ QString category(QAbstractItemModel const & model, int row) const
+ {
+ return model.data(model.index(row, 2), Qt::DisplayRole).toString();
+ }
+
+ ///
+ void paintBackground(QPainter * painter, QStyleOptionMenuItem const & opt) const
+ {
+ QComboBox * combo = static_cast<QComboBox *>(parent());
+
+ // we only want to paint a background using the style, so
+ // disable every thing else
+ QStyleOptionMenuItem sopt = opt;
+ sopt.menuRect = sopt.rect;
+ sopt.state = QStyle::State_Active | QStyle::State_Enabled;
+ sopt.checked = false;
+ sopt.text = QString();
+
+ painter->save();
+ combo->style()->drawControl(QStyle::CE_MenuItem, &sopt,
+ painter, combo->view());
+ painter->restore();
+ }
+
+ ///
+ int headerHeight(QStyleOptionMenuItem const & opt) const
+ {
+ QFontMetrics fm(opt.font);
+ return fm.height() * 8 / 10;
+ }
+ ///
+ void paintCategoryHeader(QPainter * painter, QStyleOptionMenuItem const & opt,
+ QString const & category) const
+ {
+ painter->save();
+
+ // slightly blended color
+ QColor lcol = opt.palette.text().color();
+ lcol.setAlpha(127);
+ painter->setPen(lcol);
+
+ // set 80% scaled, bold font
+ QFont font = opt.font;
+ font.setBold(true);
+ font.setWeight(QFont::Black);
+ font.setPointSize(opt.font.pointSize() * 8 / 10);
+ painter->setFont(font);
+
+ // draw the centered text
+ QFontMetrics fm(font);
+ int w = fm.width(category);
+ int x = opt.rect.x() + (opt.rect.width() - w) / 2;
+ int y = opt.rect.y() + fm.ascent();
+ int left = x;
+ int right = x + w;
+ painter->drawText(x, y, category);
+
+ // the vertical position of the line: middle of lower case chars
+ int ymid = y - 1 - fm.xHeight() / 2; // -1 for the baseline
+
+ // draw the horizontal line
+ painter->drawLine(opt.rect.x(), ymid, left - 1, ymid);
+ painter->drawLine(right + 1, ymid, opt.rect.right(), ymid);
+
+ painter->restore();
+ }
+
+