-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader_view_with_checkbox.cpp
49 lines (40 loc) · 1.16 KB
/
header_view_with_checkbox.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
44
45
46
47
48
49
#include <QtGui>
#include <QHeaderView>
#include <QStyleOptionViewItem>
#include "header_view_with_checkbox.hpp"
namespace Ui {
class CustomHeader;
}
header_view_with_checkbox::header_view_with_checkbox(Qt::Orientation orientation, QWidget * parent)
: QHeaderView(orientation, parent)
{
}
void header_view_with_checkbox::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
QHeaderView::paintSection(painter, rect, logicalIndex);
if (logicalIndex == 0) {
QStyleOptionButton option;
option.rect = QRect(3, 4, 13, 13);
if (is_selected) {
option.state = QStyle::State_On;
} else {
option.state = QStyle::State_Off;
}
this->style()->drawControl(QStyle::CE_CheckBox, &option, painter);
}
}
void header_view_with_checkbox::mousePressEvent(QMouseEvent *event)
{
int section = logicalIndexAt(event->pos());
if (event->button() == Qt::LeftButton && section == 0) {
if (is_selected) {
is_selected = false;
} else {
is_selected = true;
}
this->viewport()->update();
emit on_checkbox_click(is_selected);
}
QHeaderView::sectionClicked(section);
QHeaderView::mousePressEvent(event);
}