| 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 | |
| 4 | #ifndef QSTYLEDITEMDELEGATE_H |
| 5 | #define QSTYLEDITEMDELEGATE_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtWidgets/qabstractitemdelegate.h> |
| 9 | #include <QtCore/qstring.h> |
| 10 | #include <QtGui/qpixmap.h> |
| 11 | #include <QtCore/qvariant.h> |
| 12 | |
| 13 | QT_REQUIRE_CONFIG(itemviews); |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | class QStyledItemDelegatePrivate; |
| 18 | class QItemEditorFactory; |
| 19 | |
| 20 | class Q_WIDGETS_EXPORT QStyledItemDelegate : public QAbstractItemDelegate |
| 21 | { |
| 22 | Q_OBJECT |
| 23 | |
| 24 | public: |
| 25 | explicit QStyledItemDelegate(QObject *parent = nullptr); |
| 26 | ~QStyledItemDelegate(); |
| 27 | |
| 28 | // painting |
| 29 | void paint(QPainter *painter, |
| 30 | const QStyleOptionViewItem &option, const QModelIndex &index) const override; |
| 31 | QSize sizeHint(const QStyleOptionViewItem &option, |
| 32 | const QModelIndex &index) const override; |
| 33 | |
| 34 | // editing |
| 35 | QWidget *createEditor(QWidget *parent, |
| 36 | const QStyleOptionViewItem &option, |
| 37 | const QModelIndex &index) const override; |
| 38 | |
| 39 | void setEditorData(QWidget *editor, const QModelIndex &index) const override; |
| 40 | void setModelData(QWidget *editor, |
| 41 | QAbstractItemModel *model, |
| 42 | const QModelIndex &index) const override; |
| 43 | |
| 44 | void updateEditorGeometry(QWidget *editor, |
| 45 | const QStyleOptionViewItem &option, |
| 46 | const QModelIndex &index) const override; |
| 47 | |
| 48 | // editor factory |
| 49 | QItemEditorFactory *itemEditorFactory() const; |
| 50 | void setItemEditorFactory(QItemEditorFactory *factory); |
| 51 | |
| 52 | virtual QString displayText(const QVariant &value, const QLocale &locale) const; |
| 53 | |
| 54 | protected: |
| 55 | virtual void initStyleOption(QStyleOptionViewItem *option, |
| 56 | const QModelIndex &index) const; |
| 57 | |
| 58 | bool eventFilter(QObject *object, QEvent *event) override; |
| 59 | bool editorEvent(QEvent *event, QAbstractItemModel *model, |
| 60 | const QStyleOptionViewItem &option, const QModelIndex &index) override; |
| 61 | |
| 62 | private: |
| 63 | Q_DECLARE_PRIVATE(QStyledItemDelegate) |
| 64 | Q_DISABLE_COPY(QStyledItemDelegate) |
| 65 | }; |
| 66 | |
| 67 | QT_END_NAMESPACE |
| 68 | |
| 69 | #endif // QSTYLEDITEMDELEGATE_H |
| 70 | |