Focus and Change in Icon

  • How do I change the Icon of QPushButton when it has focus and also when it doesn't have?I had tried with hasFocus() to change the Icon but again I need to reset it by calling another function.Mainly I need to change the Icon when I change the focus with arrow keys in the keyboard.

  • Try something like this:

    navButton->setStyleSheet("QPushButton { background-color:red; } QPushButton:focus { background-color:blue; }");

    The code snippet is from "stackoverflow": because a common task was discussed there too.

    Of course instead of changing just the background color you can modify the code snippet to change the icon of your button.

  • HI thank You..I had tried it but of no use.On focus it doesnot work.I had used QtCreator for designing my forms.There I had used different icons for various states like Normal,Selected,Disabled but it doesn't work.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.