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 disable grayed out effect for icon in QPushButton
Qt 6.11 is out! See what's new in the release blog

How to disable grayed out effect for icon in QPushButton

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 7.8k Views 2 Watching
  • 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.
  • P Offline
    P Offline
    popov895
    wrote on last edited by
    #1

    Hi there!

    Here's the code:

    QIcon icon;
    icon.addFile(QStringLiteral(":/resources/login.svg"));
    icon.addFile(QStringLiteral(":/resources/login_disabled.svg"), QSize(), QIcon::Disabled);
    
    auto button = new QPushButton(tr("Login"));
    button->setIcon(icon);
    

    As you can see, I want to show the custom icon for the disabled button. But, unfortunately, the button shows a grayed out copy of that icon, but not the original. So, is it possible to show the original image for the disabled button, but not grayed out?

    Thank you.

    1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      We cant see the images. sorry pic upload is broken.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mostefa
        wrote on last edited by
        #3

        Hi @popov895

        Yes it is possible ,

        You don't have to use icon.addFile, but you have to use QIcon::addPixmap

        You have to change your code to something like this:

        QIcon icon;
        
        icon.addPixmap(QPixmap(":/resources/login.svg"), QIcon::Normal);
        icon.addPixmap(QPixmap(":/resources/login_disabled.svg"), QIcon::Disabled);
        
        auto button = new QPushButton(tr("Login"));
        button->setIcon(icon);
        

        I hope this can help you,

        1 Reply Last reply
        4
        • P Offline
          P Offline
          popov895
          wrote on last edited by
          #4

          Great, it works! Many thanks!

          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