38 lines
1017 B
C++
38 lines
1017 B
C++
#ifndef MULTILINEHEADERVIEW
|
|
#define MULTILINEHEADERVIEW
|
|
|
|
#include <QHeaderView>
|
|
|
|
struct HeaderLineStyle
|
|
{
|
|
QFont font = QFont("Microsoft YaHei", 9);
|
|
QColor color = QColor(26, 26, 26);
|
|
Qt::Alignment alignment = Qt::AlignLeft;
|
|
};
|
|
|
|
class MultiLineHeaderView : public QHeaderView
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit MultiLineHeaderView(Qt::Orientation orientation, QWidget* parent = nullptr);
|
|
|
|
void setLineSpacing(int);
|
|
void setBackgroundColor(QColor&);
|
|
void setBorderColor(QColor&);
|
|
void setSectionLineStyle(int, int, const HeaderLineStyle&); //设置某列的某行文字样式
|
|
|
|
protected:
|
|
void paintSection(QPainter*, const QRect&, int) const override;
|
|
QSize sectionSizeFromContents(int) const override;
|
|
|
|
private:
|
|
QHash<int, QMap<int, HeaderLineStyle>> m_sectionStyles; //列号->(行号->样式)
|
|
HeaderLineStyle m_defaultStyle;
|
|
QColor m_bgColor; //背景颜色
|
|
QColor m_borderColor; //边框颜色
|
|
int m_linSpacing; //行间距
|
|
};
|
|
|
|
#endif //MULTILINEHEADERVIEW
|