2021-12-08 15:10:56 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Created by Krad on 2021/12/8.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "AccountRoleComboDelegate.h"
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include "db/SQLHelper.h"
|
|
|
|
|
|
AccountRoleComboDelegate::AccountRoleComboDelegate(QWidget *parent):QItemDelegate(parent) {
|
|
|
|
|
|
SQLHelper::QueryMap("select RoleID,RoleName from Role",map);
|
|
|
|
|
|
}
|
2021-12-08 17:49:11 +08:00
|
|
|
|
//之前使用重写paint来实现了替换显示文字,效果一般
|
|
|
|
|
|
//
|
|
|
|
|
|
//void AccountRoleComboDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
|
|
|
|
|
// QItemDelegate::paint(painter, option, index);
|
|
|
|
|
|
//}
|
2021-12-08 15:10:56 +08:00
|
|
|
|
|
2021-12-08 17:49:11 +08:00
|
|
|
|
//相较于直接在paint里面操作,这是一个更好的选择,可以直接改变Display,而不影响前后景的绘制。
|
|
|
|
|
|
void AccountRoleComboDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect,
|
|
|
|
|
|
const QString &text) const {
|
2021-12-08 15:10:56 +08:00
|
|
|
|
//绘制文本
|
|
|
|
|
|
painter->drawText(option.rect, Qt::TextWordWrap | Qt::AlignCenter , map[text].toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|