tcdelegate.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef TCDELEGATE_H
  2. #define TCDELEGATE_H
  3. #include <QtCore/qglobal.h>
  4. // TCDelegate
  5. #include <QPixmap>
  6. #include <QStyledItemDelegate>
  7. class TCItemDelegate : public QStyledItemDelegate
  8. {
  9. Q_OBJECT
  10. public:
  11. enum ItemType {
  12. LINEEDIT,
  13. CHECKBOX,
  14. INTSPIN,
  15. DOUBLESPIN,
  16. PROGRESS,
  17. BUTTON,
  18. COLOR,
  19. COMBOBOX,
  20. DATETIME, //日期时间
  21. DATE, //日期
  22. TIME, //时间
  23. };
  24. explicit TCItemDelegate(QObject *parent = nullptr);
  25. explicit TCItemDelegate(ItemType type, QObject *parent = nullptr);
  26. virtual ~TCItemDelegate();
  27. void setCheckText(const QString &checkText, const QString &uncheckText);
  28. void addComboxItems(const QStringList &texts, const QStringList &userDate = QStringList());
  29. void setSpinBoxRange(double min, double max);
  30. //设置显示样式
  31. void setFormat(const QString &format);
  32. Q_SIGNALS:
  33. void valueChanged(bool value);
  34. protected:
  35. QWidget *createEditor(QWidget *parent,
  36. const QStyleOptionViewItem &option,
  37. const QModelIndex &index) const override;
  38. void setEditorData(QWidget *editor, const QModelIndex &index) const override;
  39. void setModelData(QWidget *editor,
  40. QAbstractItemModel *model,
  41. const QModelIndex &index) const override;
  42. void updateEditorGeometry(QWidget *editor,
  43. const QStyleOptionViewItem &option,
  44. const QModelIndex &) const override;
  45. bool editorEvent(QEvent *event,
  46. QAbstractItemModel *model,
  47. const QStyleOptionViewItem &option,
  48. const QModelIndex &index) override;
  49. void paint(QPainter *painter,
  50. const QStyleOptionViewItem &option,
  51. const QModelIndex &index) const override;
  52. private:
  53. class TCDateTimeDelegatePrivate *d;
  54. };
  55. #endif // TCDELEGATE_H