From 98abfcfe00ce0e09f431f39bea28aafbfc9a4d8b Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 27 Apr 2024 11:25:56 +0400 Subject: [PATCH] Use grayscale images for disabled icons --- components/misc/scalableicon.cpp | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/components/misc/scalableicon.cpp b/components/misc/scalableicon.cpp index c9062a64d0..0b30eaf2ab 100644 --- a/components/misc/scalableicon.cpp +++ b/components/misc/scalableicon.cpp @@ -77,25 +77,29 @@ namespace Misc QPixmap ScalableIcon::pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state) { - QImage img(size, QImage::Format_ARGB32); - img.fill(qRgba(0, 0, 0, 0)); - QPixmap pix = QPixmap::fromImage(img, Qt::NoFormatConversion); - { - QPainter painter(&pix); - QRect r(QPoint(0.0, 0.0), size); - this->paint(&painter, r, mode, state); - } + QPixmap pix = QPixmap(size); + pix.fill(Qt::transparent); + + QPainter painter(&pix); + QRect r(QPoint(0.0, 0.0), size); + this->paint(&painter, r, mode, state); if (mode != QIcon::Disabled) return pix; - QPixmap output(pix.size()); - output.fill(Qt::transparent); - QPainter p(&output); - p.setOpacity(0.5); - p.drawPixmap(0, 0, pix); - p.end(); + // For disabled icons use grayscale icons with 50% transparency + QImage img = pix.toImage(); + + for (int x = 0; x < img.width(); x++) + { + for (int y = 0; y < img.height(); y++) + { + QColor n = img.pixelColor(x, y); + int gray = qGray(n.red(), n.green(), n.blue()); + img.setPixelColor(x, y, QColor(gray, gray, gray, n.alpha() / 2)); + } + } - return output; + return QPixmap::fromImage(img, Qt::NoFormatConversion); } }