baseheader.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. protected:
  24. void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override;
  25. signals:
  26. void sig_Sorted(int logicalIndex, SortState state);
  27. void sig_Checked(bool checked);
  28. private slots:
  29. void OnSectionClicked(int logicalIndex);
  30. private:
  31. Qt::Alignment m_alignmentText;
  32. int m_nCurSortedIndex;
  33. bool m_bSortable;
  34. SortState m_stateCurSorted;
  35. QList<int> m_listSortDisable;
  36. bool m_bCheckable;
  37. Qt::CheckState m_checkState;
  38. //QList<SortState> m_listStates;
  39. private:
  40. QString GetCheckboxImage(Qt::CheckState state) const;
  41. };
  42. #endif // GGBASEHEADER_H