QtExamples/QtQStandardItemModelEx/ExDelegate.h
2019-10-01 11:47:23 +08:00

21 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef EXDELEGATE_H
#define EXDELEGATE_H
#include <QStyledItemDelegate>
class ExDelegate : public QStyledItemDelegate
{
public:
ExDelegate();
public:
//若是写代理的组件,那么必须要有下面这是个重写这四个函数
virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; //创建用于编辑的模型数据的widget组件如一个QComboBox组件
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override; //从数据模型获取数据显示在代理组件editor之中让其编辑
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; //代理组件editor上的数据更新到数据模型
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; //用于给widget组件设置一个合适的大小
};
#endif // EXDELEGATE_H