File indexing completed on 2026-03-29 08:30:15
0001
0002
0003
0004 #ifndef QABSTRACTITEMDELEGATE_H
0005 #define QABSTRACTITEMDELEGATE_H
0006
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtCore/qobject.h>
0009 #include <QtWidgets/qstyleoption.h>
0010
0011 QT_REQUIRE_CONFIG(itemviews);
0012
0013 QT_BEGIN_NAMESPACE
0014
0015 class QPainter;
0016 class QModelIndex;
0017 class QAbstractItemModel;
0018 class QAbstractItemView;
0019 class QHelpEvent;
0020 class QAbstractItemDelegatePrivate;
0021
0022 class Q_WIDGETS_EXPORT QAbstractItemDelegate : public QObject
0023 {
0024 Q_OBJECT
0025
0026 public:
0027
0028 enum EndEditHint {
0029 NoHint,
0030 EditNextItem,
0031 EditPreviousItem,
0032 SubmitModelCache,
0033 RevertModelCache
0034 };
0035
0036 explicit QAbstractItemDelegate(QObject *parent = nullptr);
0037 virtual ~QAbstractItemDelegate();
0038
0039
0040 virtual void paint(QPainter *painter,
0041 const QStyleOptionViewItem &option,
0042 const QModelIndex &index) const = 0;
0043
0044 virtual QSize sizeHint(const QStyleOptionViewItem &option,
0045 const QModelIndex &index) const = 0;
0046
0047
0048 virtual QWidget *createEditor(QWidget *parent,
0049 const QStyleOptionViewItem &option,
0050 const QModelIndex &index) const;
0051
0052 virtual void destroyEditor(QWidget *editor, const QModelIndex &index) const;
0053
0054 virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
0055
0056 virtual void setModelData(QWidget *editor,
0057 QAbstractItemModel *model,
0058 const QModelIndex &index) const;
0059
0060 virtual void updateEditorGeometry(QWidget *editor,
0061 const QStyleOptionViewItem &option,
0062 const QModelIndex &index) const;
0063
0064
0065 virtual bool editorEvent(QEvent *event,
0066 QAbstractItemModel *model,
0067 const QStyleOptionViewItem &option,
0068 const QModelIndex &index);
0069
0070 bool handleEditorEvent(QObject *object, QEvent *event);
0071
0072 virtual bool helpEvent(QHelpEvent *event,
0073 QAbstractItemView *view,
0074 const QStyleOptionViewItem &option,
0075 const QModelIndex &index);
0076
0077 virtual QList<int> paintingRoles() const;
0078
0079 Q_SIGNALS:
0080 void commitData(QWidget *editor);
0081 void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint = NoHint);
0082 void sizeHintChanged(const QModelIndex &);
0083
0084 protected:
0085 QAbstractItemDelegate(QObjectPrivate &, QObject *parent = nullptr);
0086
0087 private:
0088 Q_DECLARE_PRIVATE(QAbstractItemDelegate)
0089 Q_DISABLE_COPY(QAbstractItemDelegate)
0090 Q_PRIVATE_SLOT(d_func(), void _q_commitDataAndCloseEditor(QWidget*))
0091 };
0092
0093 QT_END_NAMESPACE
0094
0095 #endif