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) QToolButton(parent)
{ {
setCheckable(true); setCheckable(true);
m_originalPalette = palette(); setStyleSheet(QString("QToolButton{ background-color: %1; } QToolButton:checked{ background-color: %2; }")
connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool))); .arg(palette().button().color().name())
} .arg(palette().highlight().color().darker(150).name()));
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);
}
} }
void ButtonSwitch::doToggle(bool checked) void ButtonSwitch::doToggle(bool checked)
{ {
onToggled(checked); setChecked(checked);
} }
void ButtonSwitch::setColor(QColor color) void ButtonSwitch::setColor(QColor color)
{ {
QPalette p = m_originalPalette; setStyleSheet(QString("QToolButton{ background-color: %1; }").arg(color.name()));
p.setColor(QPalette::Button, color);
setPalette(p);
} }
void ButtonSwitch::resetColor() void ButtonSwitch::resetColor()
{ {
if (isChecked()) setStyleSheet(QString("QToolButton{ background-color: %1; } QToolButton:checked{ background-color: %2; }")
{ .arg(palette().button().color().name())
QPalette p = m_originalPalette; .arg(palette().highlight().color().darker(150).name()));
p.setColor(QPalette::Button, QColor(0x80, 0x46, 0x00));
setPalette(p);
}
else
{
setPalette(m_originalPalette);
}
} }

View File

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