-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwidget.cpp
68 lines (61 loc) · 1.66 KB
/
pwidget.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "pwidget.hpp"
PLineEdit::PLineEdit(QWidget* parent) : QLineEdit(parent)
{
}
void PLineEdit::focusInEvent(QFocusEvent* e)
{
QLineEdit::focusInEvent(e);
emit(focused());
}
PLineEdit:: ~PLineEdit()
{
}
PComboBox::PComboBox(QWidget* parent) : QComboBox(parent), arrowAlignment_(Qt::AlignRight), flat_(true)
{
setFlat(true);
setAutoFillBackground(true);
QPalette plt(palette());
plt.setColor(QPalette::Background, Qt::white);
setTextAlignment(Qt::AlignmentFlag::AlignLeft);
setPalette(plt);
QObject::connect(view(), &QAbstractItemView::pressed, this, &PComboBox::menu_pressed);
actual_itemView = view();
}
void PComboBox::setView(QAbstractItemView* itemView)
{
QObject::disconnect(actual_itemView);
QObject::connect(itemView, &QAbstractItemView::pressed, this, &PComboBox::menu_pressed);
QComboBox::setView(itemView);
}
void PComboBox::paintEvent(QPaintEvent* e)
{
if (flat()) {
QStylePainter painter(this);
painter.setPen(palette().color(QPalette::Text));
QStyleOptionComboBox opt;
initStyleOption(&opt);
QString displayText(opt.currentText);
opt.currentText = "";
painter.drawItemText(rect(), textAlignment_, palette(), true, displayText);
const QRect rcOld(opt.rect);
opt.rect = QStyle::alignedRect(Qt::LeftToRight, arrowAlignment(), QSize(16, rcOld.height()), rcOld);
painter.drawPrimitive(QStyle::PE_IndicatorArrowDown, opt);
opt.rect = rcOld;
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
}
else {
QComboBox::paintEvent(e);
}
}
void PComboBox::setFlat(bool flat)
{
flat_ = flat;
}
void PComboBox::setArrowAlignment(Qt::Alignment a)
{
arrowAlignment_ = a;
}
void PComboBox::setTextAlignment(Qt::Alignment a)
{
textAlignment_ = a;
}