baseheader.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef GGBASEHEADER_H
  2. #define GGBASEHEADER_H
  3. #include <QWidget>
  4. #include <QHeaderView>
  5. class BaseHeader : public QHeaderView
  6. {
  7. Q_OBJECT
  8. public:
  9. enum SortState
  10. {
  11. Disable = -1,
  12. NotSort = 0,
  13. Asc = 1,
  14. Desc = 2
  15. };
  16. public:
  17. explicit BaseHeader(QWidget *parent = nullptr, Qt::Orientation orientation = Qt::Horizontal, Qt::Alignment flags = Qt::AlignLeft|Qt::AlignVCenter);
  18. void SetTextAlignment(Qt::Alignment flags);
  19. void SetSortable(bool value, const QList<int> &notSortList = QList<int>());
  20. void SetCheckable(bool value);
  21. void SetChecked(Qt::CheckState state);
  22. QString GetText(int logicalIndex);//获取表头名称 add by wl 2023-06-26
  23. Qt::CheckState GetChecked() const { return m_checkState; } /* 获取checkBox状态,add by ztl,2025-08-22 */
  24. protected:
  25. void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override;
  26. signals:
  27. void sig_Sorted(int logicalIndex, SortState state);
  28. void sig_Checked(bool checked);
  29. private slots:
  30. void OnSectionClicked(int logicalIndex);
  31. private:
  32. Qt::Alignment m_alignmentText;
  33. int m_nCurSortedIndex;
  34. bool m_bSortable;
  35. SortState m_stateCurSorted;
  36. QList<int> m_listSortDisable;
  37. bool m_bCheckable;
  38. Qt::CheckState m_checkState;
  39. //QList<SortState> m_listStates;
  40. private:
  41. QString GetCheckboxImage(Qt::CheckState state) const;
  42. };
  43. #endif // GGBASEHEADER_H