Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
The disabled state is visible by the button border color.
--- a/QTfrontend/ui/widget/togglebutton.cpp Sat Mar 17 23:55:32 2018 +0300
+++ b/QTfrontend/ui/widget/togglebutton.cpp Sat Mar 17 22:26:02 2018 +0100
@@ -24,22 +24,32 @@
{
setCheckable(true);
- QPixmap pm(":/res/btnDisabled.png");
+ QPixmap pixOffOverlay(":/res/btnDisabled.png");
QPainter * painter = new QPainter();
- pmChecked.load(img);
- pmDisabled.load(img);
-
- pmDisabled.setDevicePixelRatio(pm.devicePixelRatio());
+ QPixmap pixOn = QPixmap(img);
+ QPixmap pixOff = QPixmap(img);
- setMaximumWidth(pmChecked.width() + 6);
+ // Use the same image for disabled (i.e. non-clickable) button.
+ // The default would be gray which is a little bit hard on the eye.
+ // The disabled state is communicated to the user by the button
+ // border, which turns gray.
+ icoChecked.addPixmap(pixOn, QIcon::Normal);
+ icoChecked.addPixmap(pixOn, QIcon::Disabled);
- painter->begin(&pmDisabled);
- painter->drawPixmap(pmDisabled.rect(), pm);
+ pixOff.setDevicePixelRatio(pixOffOverlay.devicePixelRatio());
+
+ setMaximumWidth(pixOn.width() + 6);
+
+ painter->begin(&pixOff);
+ painter->drawPixmap(pixOff.rect(), pixOffOverlay);
painter->end();
- setIconSize(pmDisabled.size());
- setIcon(pmDisabled);
+ icoUnchecked.addPixmap(pixOff, QIcon::Normal);
+ icoUnchecked.addPixmap(pixOff, QIcon::Disabled);
+
+ setIconSize(pixOff.size());
+ setIcon(icoUnchecked);
connect(this, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
}
@@ -50,5 +60,5 @@
void ToggleButtonWidget::eventToggled(bool checked)
{
- setIcon(checked ? pmChecked : pmDisabled);
+ setIcon(checked ? icoChecked : icoUnchecked);
}
--- a/QTfrontend/ui/widget/togglebutton.h Sat Mar 17 23:55:32 2018 +0300
+++ b/QTfrontend/ui/widget/togglebutton.h Sat Mar 17 22:26:02 2018 +0100
@@ -25,6 +25,7 @@
#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>
+#include <QIcon>
class ToggleButtonWidget : public QPushButton
{
@@ -33,8 +34,8 @@
ToggleButtonWidget(QWidget * parent, QString img);
~ToggleButtonWidget();
private:
- QPixmap pmChecked;
- QPixmap pmDisabled;
+ QIcon icoUnchecked;
+ QIcon icoChecked;
private slots:
void eventToggled(bool checked);
};