1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

ButtonSwitch: use stylesheet instead of fiddling with the color palette. Fixes some inital color state issues

This commit is contained in:
f4exb 2022-05-19 17:51:51 +02:00
parent 6023aa826f
commit 01dc1a9490
2 changed files with 8 additions and 41 deletions

View File

@ -5,51 +5,24 @@ ButtonSwitch::ButtonSwitch(QWidget* parent) :
QToolButton(parent)
{
setCheckable(true);
m_originalPalette = palette();
connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
}
void ButtonSwitch::onToggled(bool checked)
{
blockSignals(true);
setChecked(checked);
blockSignals(false);
if (checked)
{
QPalette p = m_originalPalette;
p.setColor(QPalette::Button, QColor(0x80, 0x46, 0x00));
setPalette(p);
}
else
{
setPalette(m_originalPalette);
}
setStyleSheet(QString("QToolButton{ background-color: %1; } QToolButton:checked{ background-color: %2; }")
.arg(palette().button().color().name())
.arg(palette().highlight().color().darker(150).name()));
}
void ButtonSwitch::doToggle(bool checked)
{
onToggled(checked);
setChecked(checked);
}
void ButtonSwitch::setColor(QColor color)
{
QPalette p = m_originalPalette;
p.setColor(QPalette::Button, color);
setPalette(p);
setStyleSheet(QString("QToolButton{ background-color: %1; }").arg(color.name()));
}
void ButtonSwitch::resetColor()
{
if (isChecked())
{
QPalette p = m_originalPalette;
p.setColor(QPalette::Button, QColor(0x80, 0x46, 0x00));
setPalette(p);
}
else
{
setPalette(m_originalPalette);
}
setStyleSheet(QString("QToolButton{ background-color: %1; } QToolButton:checked{ background-color: %2; }")
.arg(palette().button().color().name())
.arg(palette().highlight().color().darker(150).name()));
}

View File

@ -13,12 +13,6 @@ public:
void doToggle(bool checked);
void setColor(QColor color);
void resetColor();
private slots:
void onToggled(bool checked);
private:
QPalette m_originalPalette;
};
#endif // INCLUDE_BUTTONSWITCH_H