-
Notifications
You must be signed in to change notification settings - Fork 1
/
beanpacketsloggerheaderview.cpp
43 lines (35 loc) · 1.07 KB
/
beanpacketsloggerheaderview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "beanpacketsloggerheaderview.h"
#include <QHeaderView>
bool isChecked = false;
BeanPacketsLoggerHeaderView::BeanPacketsLoggerHeaderView(Qt::Orientation orientation, QWidget * parent)
: QHeaderView(orientation, parent)
{
}
BeanPacketsLoggerHeaderView::~BeanPacketsLoggerHeaderView() = default;
void BeanPacketsLoggerHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();
if (logicalIndex == 0) {
QStyleOptionButton option;
option.rect = QRect(1,3,20,20);
if (isChecked) {
option.state = QStyle::State_On;
} else {
option.state = QStyle::State_Off;
}
this->style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &option, painter);
}
}
void BeanPacketsLoggerHeaderView::mousePressEvent(QMouseEvent *event)
{
isChecked = !isChecked;
this->update();
QHeaderView::mousePressEvent(event);
redrawCheckBox();
}
void BeanPacketsLoggerHeaderView::redrawCheckBox()
{
viewport()->update();
}