How to disable grayed out effect for icon in QPushButton
Solved
General and Desktop
-
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.
-
Hi
We cant see the images. sorry pic upload is broken. -
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,