Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qabstractitemdelegate.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QABSTRACTITEMDELEGATE_H
6#define QABSTRACTITEMDELEGATE_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtCore/qobject.h>
10#include <QtWidgets/qstyleoption.h>
11
13
14QT_BEGIN_NAMESPACE
15
16class QPainter;
17class QModelIndex;
18class QAbstractItemModel;
19class QAbstractItemView;
20class QHelpEvent;
21class QAbstractItemDelegatePrivate;
22
23class Q_WIDGETS_EXPORT QAbstractItemDelegate : public QObject
24{
25 Q_OBJECT
26
27public:
28
29 enum EndEditHint {
30 NoHint,
31 EditNextItem,
32 EditPreviousItem,
33 SubmitModelCache,
34 RevertModelCache
35 };
36
37 explicit QAbstractItemDelegate(QObject *parent = nullptr);
38 virtual ~QAbstractItemDelegate();
39
40 // painting
41 virtual void paint(QPainter *painter,
42 const QStyleOptionViewItem &option,
43 const QModelIndex &index) const = 0;
44
45 virtual QSize sizeHint(const QStyleOptionViewItem &option,
46 const QModelIndex &index) const = 0;
47
48 // editing
49 virtual QWidget *createEditor(QWidget *parent,
50 const QStyleOptionViewItem &option,
51 const QModelIndex &index) const;
52
53 virtual void destroyEditor(QWidget *editor, const QModelIndex &index) const;
54
55 virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
56
57 virtual void setModelData(QWidget *editor,
58 QAbstractItemModel *model,
59 const QModelIndex &index) const;
60
61 virtual void updateEditorGeometry(QWidget *editor,
62 const QStyleOptionViewItem &option,
63 const QModelIndex &index) const;
64
65 // for non-widget editors
66 virtual bool editorEvent(QEvent *event,
67 QAbstractItemModel *model,
68 const QStyleOptionViewItem &option,
69 const QModelIndex &index);
70 // for widget editors
71 bool handleEditorEvent(QObject *object, QEvent *event);
72
73 virtual bool helpEvent(QHelpEvent *event,
74 QAbstractItemView *view,
75 const QStyleOptionViewItem &option,
76 const QModelIndex &index);
77
78 virtual QList<int> paintingRoles() const;
79
80Q_SIGNALS:
81 void commitData(QWidget *editor);
82 void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint = NoHint);
83 void sizeHintChanged(const QModelIndex &);
84
85protected:
86 QAbstractItemDelegate(QObjectPrivate &, QObject *parent = nullptr);
87
88private:
89 Q_DECLARE_PRIVATE(QAbstractItemDelegate)
90 Q_DISABLE_COPY(QAbstractItemDelegate)
91 Q_PRIVATE_SLOT(d_func(), void _q_commitDataAndCloseEditor(QWidget*))
92};
93
94QT_END_NAMESPACE
95
96#endif // QABSTRACTITEMDELEGATE_H
The QAbstractItemDelegate class is used to display and edit data items from a model.
\inmodule QtCore
QT_REQUIRE_CONFIG(itemviews)
static bool editorHandlesKeyEvent(QWidget *editor, const QKeyEvent *event)