Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPushButton - not working setIcon in Active state



  • QIcon icon;
    icon.addFile(":/25.png", QSize(), QIcon::Normal); - ok
    icon.addFile(":/25_hover.png", QSize(), QIcon::Active); - fails
    icon.addFile(":/25_disabled.png", QSize(), QIcon::Disabled); - ok

    QPushButton button;
    button.setIcon(icon);

    When mouse hover the button (button is Active), but icon of the button in state Normal, why?


  • Moderators

    The Active state can mean different things for different widgets. For push button hover and active are two different things. A button becomes active when it has focus (e.g. after a click or via keyboard tabbing to it). Hovering is not the same as it can occur over an inactive button too.
    To style a button when mouse hovers over it you can use a stylesheet.



  • Chris, thank you!



  • [quote author="Chris Kawa" date="1423590349"] A button becomes active when it has focus (e.g. after a click or via keyboard tabbing to it). Hovering is not the same as it can occur over an inactive button too.[/quote]

    Sorry, Chris, do you know when QCheckBox becomes Active?


  • Moderators

    bq. do you know when QCheckBox becomes Active?

    An intuition would suggest the same situation - clicked or navigated via keyboard, but apparently it doesn't respect the icon change on that soo... I don't know. Possibly a Qt bug?



  • Finally, I haven't could learn, when QCheckBox becomes Active and solved the problem via inheritance from QCheckBox.

    Stylesheet for QCheckBox is very limited.

    Thank you for help!


Log in to reply