| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #ifndef TCDELEGATE_H
- #define TCDELEGATE_H
- #include <QtCore/qglobal.h>
- // TCDelegate
- #include <QPixmap>
- #include <QStyledItemDelegate>
- class TCItemDelegate : public QStyledItemDelegate
- {
- Q_OBJECT
- public:
- enum ItemType {
- LINEEDIT,
- CHECKBOX,
- INTSPIN,
- DOUBLESPIN,
- PROGRESS,
- BUTTON,
- COLOR,
- COMBOBOX,
- DATETIME, //日期时间
- DATE, //日期
- TIME, //时间
- };
- explicit TCItemDelegate(QObject *parent = nullptr);
- explicit TCItemDelegate(ItemType type, QObject *parent = nullptr);
- virtual ~TCItemDelegate();
- void setCheckText(const QString &checkText, const QString &uncheckText);
- void addComboxItems(const QStringList &texts, const QStringList &userDate = QStringList());
- void setSpinBoxRange(double min, double max);
- //设置显示样式
- void setFormat(const QString &format);
- Q_SIGNALS:
- void valueChanged(bool value);
- protected:
- QWidget *createEditor(QWidget *parent,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
- void setEditorData(QWidget *editor, const QModelIndex &index) const override;
- void setModelData(QWidget *editor,
- QAbstractItemModel *model,
- const QModelIndex &index) const override;
- void updateEditorGeometry(QWidget *editor,
- const QStyleOptionViewItem &option,
- const QModelIndex &) const override;
- bool editorEvent(QEvent *event,
- QAbstractItemModel *model,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) override;
- void paint(QPainter *painter,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const override;
- private:
- class TCDateTimeDelegatePrivate *d;
- };
- #endif // TCDELEGATE_H
|