DelegateCheckBox.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef __DELEGATE_CHECKBOX_H__
  2. #define __DELEGATE_CHECKBOX_H__
  3. #include <QStyledItemDelegate>
  4. class DelegateCheckBox : public QStyledItemDelegate
  5. {
  6. Q_OBJECT
  7. public:
  8. explicit DelegateCheckBox(QObject *parent = nullptr);
  9. ~DelegateCheckBox() override;
  10. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
  11. void setEditorData(QWidget *editor, const QModelIndex &index) const override;
  12. void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
  13. void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
  14. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
  15. protected:
  16. bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
  17. private:
  18. /* 获取图片 */
  19. QString GetCheckboxImage(Qt::CheckState state) const;
  20. };
  21. #endif // __DELEGATE_CHECKBOX_H__