Don't gray out images of disabled ToggleButtons as its a little too hard on the eyes
authorWuzzy <Wuzzy2@mail.ru>
Sat, 17 Mar 2018 22:26:02 +0100
changeset 13248 480dcc29391c
parent 13245 950186baa764
child 13249 d49bd0dd735d
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.
QTfrontend/ui/widget/togglebutton.cpp
QTfrontend/ui/widget/togglebutton.h
--- 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);
 };