Refactor AccountRoleComboDelegate.
This commit is contained in:
@@ -3,22 +3,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "AccountRoleComboDelegate.h"
|
#include "AccountRoleComboDelegate.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "db/SQLHelper.h"
|
#include "db/SQLHelper.h"
|
||||||
AccountRoleComboDelegate::AccountRoleComboDelegate(QWidget *parent):QItemDelegate(parent) {
|
AccountRoleComboDelegate::AccountRoleComboDelegate(QWidget *parent):QItemDelegate(parent) {
|
||||||
SQLHelper::QueryMap("select RoleID,RoleName from Role",map);
|
SQLHelper::QueryMap("select RoleID,RoleName from Role", mRoleMap);
|
||||||
}
|
}
|
||||||
//之前使用重写paint来实现了替换显示文字,效果一般
|
|
||||||
//
|
|
||||||
//void AccountRoleComboDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
|
||||||
// QItemDelegate::paint(painter, option, index);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//相较于直接在paint里面操作,这是一个更好的选择,可以直接改变Display,而不影响前后景的绘制。
|
//相较于直接在paint里面操作,这是一个更好的选择,可以直接改变Display,而不影响前后景的绘制。
|
||||||
void AccountRoleComboDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect,
|
void AccountRoleComboDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect,
|
||||||
const QString &text) const {
|
const QString &text) const {
|
||||||
//绘制文本
|
//绘制文本
|
||||||
painter->drawText(option.rect, Qt::TextWordWrap | Qt::AlignCenter , map[text].toString());
|
painter->drawText(option.rect, Qt::TextWordWrap | Qt::AlignCenter , mRoleMap[text].toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
|
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QRect &rect, const QString &text) const override ;
|
const QRect &rect, const QString &text) const override ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAbstractItemModel* model = nullptr;
|
QMap<QString,QVariant> mRoleMap ;
|
||||||
QMap<QString,QVariant> map ;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GUI_ACCOUNTROLECOMBODELEGATE_H
|
#endif //GUI_ACCOUNTROLECOMBODELEGATE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user