Change collapsible title from labels to buttons, connect toggled signal to expand/collapse

This commit is contained in:
Dan Paulat 2023-06-26 22:51:32 -05:00
parent 300091dbe1
commit 7ff9feba25
2 changed files with 36 additions and 56 deletions

View file

@ -39,7 +39,7 @@ CollapsibleGroup::CollapsibleGroup(const QString& title, QWidget* parent) :
ui(new Ui::CollapsibleGroup)
{
ui->setupUi(this);
ui->titleLabel->setText(title);
ui->titleButton->setText(title);
p->Initialize();
}
@ -51,6 +51,21 @@ CollapsibleGroup::~CollapsibleGroup()
void CollapsibleGroupImpl::Initialize()
{
self_->Expand();
QObject::connect(self_->ui->titleButton,
&QAbstractButton::toggled,
self_,
[this](bool checked)
{
if (checked)
{
self_->Expand();
}
else
{
self_->Collapse();
}
});
}
void CollapsibleGroup::SetContentsLayout(QLayout* layout)
@ -60,14 +75,16 @@ void CollapsibleGroup::SetContentsLayout(QLayout* layout)
void CollapsibleGroup::SetTitle(const QString& title)
{
ui->titleLabel->setText(title);
ui->titleButton->setText(title);
}
void CollapsibleGroup::Collapse()
{
// Update the title frame
ui->arrowLabel->setMaximumSize(8, 16);
ui->arrowLabel->setPixmap(p->kCollapsedIcon_.pixmap(8, 16));
if (ui->titleButton->isChecked())
{
ui->titleButton->setChecked(false);
}
// Hide the group contents
ui->contentsFrame->setVisible(false);
@ -76,8 +93,10 @@ void CollapsibleGroup::Collapse()
void CollapsibleGroup::Expand()
{
// Update the title frame
ui->arrowLabel->setMaximumSize(16, 16);
ui->arrowLabel->setPixmap(p->kExpandedIcon_.pixmap(16, 16));
if (!ui->titleButton->isChecked())
{
ui->titleButton->setChecked(true);
}
// Show the group contents
ui->contentsFrame->setVisible(true);

View file

@ -17,18 +17,6 @@
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="titleFrame">
<property name="frameShape">
@ -51,50 +39,23 @@
<number>1</number>
</property>
<item>
<widget class="QLabel" name="arrowLabel">
<property name="minimumSize">
<size>
<width>16</width>
<height>0</height>
</size>
<widget class="QPushButton" name="titleButton">
<property name="styleSheet">
<string notr="true">background: transparent; border: none; color: palette(window-text); text-align: left;</string>
</property>
<property name="maximumSize">
<size>
<width>8</width>
<height>16</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../../../scwx-qt.qrc">:/res/icons/font-awesome-6/angle-down-solid.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="titleLabel">
<property name="text">
<string>Title</string>
</property>
<property name="icon">
<iconset resource="../../../../scwx-qt.qrc">
<normaloff>:/res/icons/font-awesome-6/angle-right-solid.svg</normaloff>
<normalon>:/res/icons/font-awesome-6/angle-down-solid.svg</normalon>:/res/icons/font-awesome-6/angle-right-solid.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>