buttondelegate.h 923 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef BUTTONDELEGATE_H
  2. #define BUTTONDELEGATE_H
  3. #include "basedelegate.h"
  4. #include <QMap>
  5. struct stButtonInfo
  6. {
  7. QString strText;
  8. int nWidth;
  9. int nHeight;
  10. };
  11. ///
  12. /// 为指定列设置按钮代理
  13. ///
  14. class ButtonDelegate : public BaseDelegate
  15. {
  16. Q_OBJECT
  17. public:
  18. explicit ButtonDelegate(QObject *parent = nullptr);
  19. void CreateButton(int nCol, QString strBtnText, int nBtnWidth, int nBtnHeight);
  20. public:
  21. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
  22. bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
  23. signals:
  24. // 发出带有被点击的QModelIndex和按钮索引的信号
  25. void SignalButtonClicked(const QModelIndex &index, int nBtnIndex) const;
  26. private:
  27. QMap<int, QList<stButtonInfo>> m_mapBtnInfo;
  28. };
  29. #endif // BUTTONDELEGATE_H