Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to control style of disabled qicons
QtWS25 Last Chance

How to control style of disabled qicons

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 884 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HowitzerDev
    wrote on last edited by
    #1

    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,
    Adam

    QT 5.15

    B 1 Reply Last reply
    0
    • H HowitzerDev

      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,
      Adam

      QT 5.15

      B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      @HowitzerDev Then also design the "disabled" ones and add them to the QIcon by QIcon::addPixmap(pixmap, QIcon::Disabled)

      H 1 Reply Last reply
      3
      • B Bonnie

        @HowitzerDev Then also design the "disabled" ones and add them to the QIcon by QIcon::addPixmap(pixmap, QIcon::Disabled)

        H Offline
        H Offline
        HowitzerDev
        wrote on last edited by
        #3

        @Bonnie We can do that but we have multiple hundreds of icons so it's last resort.

        S 1 Reply Last reply
        0
        • H Offline
          H Offline
          HowitzerDev
          wrote on last edited by
          #4

          Any other ideas?

          1 Reply Last reply
          0
          • H HowitzerDev

            @Bonnie We can do that but we have multiple hundreds of icons so it's last resort.

            S Offline
            S Offline
            StarterKit
            wrote on last edited by
            #5

            @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 of addPixmap() 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?)

            Ronel_qtmasterR 1 Reply Last reply
            0
            • S StarterKit

              @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 of addPixmap() 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?)

              Ronel_qtmasterR Offline
              Ronel_qtmasterR Offline
              Ronel_qtmaster
              wrote on last edited by
              #6

              @StarterKit you can create a custom style that will not decrease the background color of the button, therefore won't affect the button icon

              S 1 Reply Last reply
              0
              • Ronel_qtmasterR Ronel_qtmaster

                @StarterKit you can create a custom style that will not decrease the background color of the button, therefore won't affect the button icon

                S Offline
                S Offline
                StarterKit
                wrote on last edited by StarterKit
                #7

                @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
                
                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved