15 using QToolButton::QToolButton;
18 void paintEvent(QPaintEvent*)
override
21 p.setRenderHint(QPainter::Antialiasing);
23 const auto& pal = palette();
26 p.fillRect(rect(), pal.color(QPalette::Midlight));
28 p.fillRect(rect(), pal.color(QPalette::Midlight).darker(110));
32 p.setPen(pal.color(QPalette::Highlight));
33 p.drawRect(rect().adjusted(0, 0, -1, -1));
36 const int arrowSize = 6;
38 const int arrowY = (height() - arrowSize) / 2;
41 p.setBrush(pal.color(QPalette::WindowText));
46 arrow << QPointF(arrowX, arrowY) << QPointF(arrowX + arrowSize, arrowY)
47 << QPointF(arrowX + arrowSize / 2.0, arrowY + arrowSize);
51 arrow << QPointF(arrowX, arrowY)
52 << QPointF(arrowX + arrowSize, arrowY + arrowSize / 2.0)
53 << QPointF(arrowX, arrowY + arrowSize);
57 p.setPen(pal.color(QPalette::WindowText));
58 const int textLeft = arrowX + arrowSize + 8;
59 QRect textRect(textLeft, 0, width() - textLeft, height());
60 p.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text());
73 m_header->setText(title);
74 m_header->setCheckable(
true);
75 m_header->setChecked(
true);
76 m_header->setFocusPolicy(Qt::TabFocus);
77 m_header->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
78 m_header->setFixedHeight(24);
80 m_contentWidget =
new QWidget(
this);
82 auto* mainLayout =
new QVBoxLayout(
this);
83 mainLayout->setContentsMargins(0, 0, 0, 0);
84 mainLayout->setSpacing(0);
85 mainLayout->addWidget(m_header);
86 mainLayout->addWidget(m_contentWidget);
88 connect(m_header, &QToolButton::toggled,
this, [
this](
bool checked) {
89 m_contentWidget->setVisible(checked);
94 void setContentLayout(QLayout* layout)
96 if(m_contentWidget->layout())
99 "CollapsibleSection::setContentLayout: content layout already set, ignoring.");
102 layout->setContentsMargins(10, 8, 10, 8);
103 m_contentWidget->setLayout(layout);
106 void setExpanded(
bool expanded) { m_header->setChecked(expanded); }
107 bool isExpanded()
const {
return m_header->isChecked(); }
111 QWidget* m_contentWidget =
nullptr;