OGS
CheckboxDelegate.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <QItemDelegate>
18
19class QWidget;
20class QRect;
21
28class CheckboxDelegate : public QItemDelegate
29{
30 Q_OBJECT
31
32public:
34 explicit CheckboxDelegate(QObject* parent = nullptr);
35
37 void paint(QPainter* painter, const QStyleOptionViewItem& option,
38 const QModelIndex& index) const override;
39
41 bool editorEvent(QEvent* event, QAbstractItemModel* model,
42 const QStyleOptionViewItem& option,
43 const QModelIndex& index) override;
44
45 QSize sizeHint(const QStyleOptionViewItem& option,
46 const QModelIndex& index) const override;
47
48private:
49 QRect checkboxRect(const QStyleOptionViewItem& viewItemStyleOptions) const;
50};
CheckboxDelegate modifies a model view to display boolean values as checkboxes.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Paints a checkbox. This overrides the default painting of a combo box.
QRect checkboxRect(const QStyleOptionViewItem &viewItemStyleOptions) const
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Handles the click events and sets the model data.
CheckboxDelegate(QObject *parent=nullptr)
Constructor.