How to control style of disabled qicons
-
Hello,
We are designing new icons for our QT app. Some of them are black and white and when the button holding the icon is disabled, it hardly lightens the icon color at all. The toolbar back color is light grey. The result of this is that you can't easily tell the button is disabled because the difference between enabled and disabled images is small.
Is there a way in qss to simply make the disabled icons much lighter? Basically if the pixel is black in the enabled pixmap, make it close to white in the disabled one.
What are the best options?
I saw this thread : https://stackoverflow.com/questions/30865189/change-disabled-qicon-tint-color but generatedIconPixmap indicates it needs style information to do the change.
Thanks,
AdamQT 5.15
-
@HowitzerDev Then also design the "disabled" ones and add them to the QIcon by
QIcon::addPixmap(pixmap, QIcon::Disabled)
-
Any other ideas?
-
@HowitzerDev, was you able to solve your problem?
I faced the same issue - my app has black&white icons and when icon is disabled the difference is barely visible.
Usage ofaddPixmap()
isn't a good option as I simply load icons from file currently. I don't really want to add one more file for each icon.
Is there any way to incorporate a disabled image inside ICO file format? (i.e. I if I make ICO from several PNG images - is it possible to add there a separate disabled image?) -
@StarterKit you can create a custom style that will not decrease the background color of the button, therefore won't affect the button icon
-
@Ronel_qtmaster, I need to affect the button icon. I.e. I need to have grey color of my icon instead of black for disabled button. But Qt changes it very little and icon still looks like a completely black and indistinguishable from an active button.
As of now I went with below code to adjust alpha-channel for each of images inside QIcon. Not very effecive but icons are small so I can afford it.
This way I have pretty grey icons for disabled buttons.
But if someone knows better way to do it, I would like to know.def add_disabled_state(icon: QIcon) -> QIcon: disabled_icons = [] for size in icon.availableSizes(): icon_image = icon.pixmap(size).toImage() for y in range(icon_image.height()): for x in range(icon_image.width()): pixel_color = icon_image.pixelColor(x, y) pixel_color.setAlpha(pixel_color.alpha() / 5) icon_image.setPixelColor(x, y, pixel_color) disabled_icons.append(QPixmap.fromImage(icon_image)) for disabled_image in disabled_icons: icon.addPixmap(disabled_image, mode=QIcon.Mode.Disabled) return icon