| 1179 | } |
| 1180 | |
| 1181 | void WizMessageSelectorItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const |
| 1182 | { |
| 1183 | // QStyleOptionViewItem opt(option); |
| 1184 | QStyleOptionViewItem opt = option; |
| 1185 | initStyleOption(&opt, index); |
| 1186 | //NOTE:QCombobox 的项目的背景css颜色样式无效,需要通过绘制实现。 |
| 1187 | if (option.state & QStyle::State_Selected) |
| 1188 | { |
| 1189 | opt.palette.setColor(QPalette::Text, QColor(Qt::black)); |
| 1190 | opt.palette.setColor(QPalette::WindowText, QColor(Qt::black)); |
| 1191 | opt.palette.setColor(QPalette::HighlightedText, QColor(Qt::black)); |
| 1192 | } |
| 1193 | if (option.state & QStyle::State_MouseOver) |
| 1194 | { |
| 1195 | painter->fillRect(option.rect, QBrush(QColor("#3397db"))); |
| 1196 | opt.palette.setColor(QPalette::Text, QColor(Qt::white)); |
| 1197 | opt.palette.setColor(QPalette::WindowText, QColor(Qt::white)); |
| 1198 | opt.palette.setColor(QPalette::HighlightedText, QColor(Qt::white)); |
| 1199 | } |
| 1200 | |
| 1201 | painter->save(); |
| 1202 | |
| 1203 | painter->setPen(QPen(opt.palette.color(QPalette::Text))); |
| 1204 | painter->setFont(opt.font); |
| 1205 | |
| 1206 | const int nMargin = 5; |
| 1207 | const int nIconSize = 20; |
| 1208 | QRect rcItem = opt.rect; |
| 1209 | QRect rcIcon(rcItem.left() + nMargin, rcItem.top() + (rcItem.height() - nIconSize) / 2, nIconSize , nIconSize); |
| 1210 | painter->drawPixmap(rcIcon, opt.icon.pixmap(nIconSize, nIconSize)); |
| 1211 | QRect rcText(rcIcon.right() + nMargin + 1, rcItem.top(), rcItem.width() - rcIcon.width() - nMargin * 2, rcItem.height()); |
| 1212 | painter->drawText(rcText, Qt::AlignLeft |Qt::AlignVCenter, opt.text); |
| 1213 | |
| 1214 | painter->restore(); |
| 1215 | } |
| 1216 | |
| 1217 | WizSortFilterProxyModel::WizSortFilterProxyModel(QObject* parent) |
| 1218 | : QSortFilterProxyModel(parent) |