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 QITEMDELEGATE_H
5#define QITEMDELEGATE_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
13QT_REQUIRE_CONFIG(itemviews);
14
15QT_BEGIN_NAMESPACE
16
17class QItemDelegatePrivate;
18class QItemEditorFactory;
19
20class Q_WIDGETS_EXPORT QItemDelegate : public QAbstractItemDelegate
21{
22 Q_OBJECT
23 Q_PROPERTY(bool clipping READ hasClipping WRITE setClipping)
24
25public:
26 explicit QItemDelegate(QObject *parent = nullptr);
27 ~QItemDelegate();
28
29 bool hasClipping() const;
30 void setClipping(bool clip);
31
32 // painting
33 void paint(QPainter *painter,
34 const QStyleOptionViewItem &option,
35 const QModelIndex &index) const override;
36 QSize sizeHint(const QStyleOptionViewItem &option,
37 const QModelIndex &index) const override;
38
39 // editing
40 QWidget *createEditor(QWidget *parent,
41 const QStyleOptionViewItem &option,
42 const QModelIndex &index) const override;
43
44 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
45 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
46
47 void updateEditorGeometry(QWidget *editor,
48 const QStyleOptionViewItem &option,
49 const QModelIndex &index) const override;
50
51 // editor factory
52 QItemEditorFactory *itemEditorFactory() const;
53 void setItemEditorFactory(QItemEditorFactory *factory);
54
55protected:
56 virtual void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
57 const QRect &rect, const QString &text) const;
58 virtual void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option,
59 const QRect &rect, const QPixmap &pixmap) const;
60 virtual void drawFocus(QPainter *painter, const QStyleOptionViewItem &option,
61 const QRect &rect) const;
62 virtual void drawCheck(QPainter *painter, const QStyleOptionViewItem &option,
63 const QRect &rect, Qt::CheckState state) const;
64 void drawBackground(QPainter *painter, const QStyleOptionViewItem &option,
65 const QModelIndex &index) const;
66
67 void doLayout(const QStyleOptionViewItem &option,
68 QRect *checkRect, QRect *iconRect, QRect *textRect, bool hint) const;
69
70 QRect rect(const QStyleOptionViewItem &option, const QModelIndex &index, int role) const;
71
72 bool eventFilter(QObject *object, QEvent *event) override;
73 bool editorEvent(QEvent *event, QAbstractItemModel *model,
74 const QStyleOptionViewItem &option, const QModelIndex &index) override;
75
76 QStyleOptionViewItem setOptions(const QModelIndex &index,
77 const QStyleOptionViewItem &option) const;
78
79 QPixmap decoration(const QStyleOptionViewItem &option, const QVariant &variant) const;
80
81 static QPixmap selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled);
82
83 QRect doCheck(const QStyleOptionViewItem &option, const QRect &bounding,
84 const QVariant &variant) const;
85 QRect textRectangle(QPainter *painter, const QRect &rect,
86 const QFont &font, const QString &text) const;
87
88private:
89 Q_DECLARE_PRIVATE(QItemDelegate)
90 Q_DISABLE_COPY(QItemDelegate)
91};
92
93QT_END_NAMESPACE
94
95#endif // QITEMDELEGATE_H
96

source code of qtbase/src/widgets/itemviews/qitemdelegate.h