spyder-ide / qtawesome

Iconic fonts in PyQt and PySide applications

Home Page:https://qtawesome.readthedocs.io/en/latest/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Selected` option doesn't change `QPushButton` icon only icon color

r-bash opened this issue · comments

commented

Hello,

I've got:

  • Python==3.9.13
  • PySide6==6.5.0
  • QtPy==2.3.1

and I am trying to create a QPushButton which will be changing the icon on a "selected" mode/state but unfortunatelly it is not working. In other words, I am trying to create toggle QPushButton. To create the QPushButton I've taken the example from your documentation( https://qtawesome.readthedocs.io/en/latest/usage.html#examples):

# Toggle
toggle_icon = qta.icon('fa5s.home', selected='fa5s.balance-scale',
                        color_off='black',
                        color_off_active='blue',
                        color_on='orange',
                        color_on_active='yellow')
toggle_button = QtWidgets.QPushButton(toggle_icon, 'Toggle')
toggle_button.setCheckable(True)

Could I ask you for help?
Thanks

Hi @r-bash thank you for checking out QtAwesome! Regarding what you want to achieve, I think the kwarg that needs to be passed is active to toggle between icons. So basically code could do something like:

# Toggle
toggle_icon = qta.icon('fa5s.home', active='fa5s.balance-scale',
                        color_off='black',
                        color_off_active='blue',
                        color_on='orange',
                        color_on_active='yellow')
toggle_button = QtWidgets.QPushButton(toggle_icon, 'Toggle')
toggle_button.setCheckable(True)

With that you should see something like:

toggle

Some other examples that show this behavior are the piece of code commented as Styling and the one commented as Stack icons. Let us know if the info above helps!

Note: Not totally sure if this should be modified in the example or if there is an issue with the selected vs active option. What do you think @ccordoba12 ?

Not totally sure if this should be modified in the example or if there is an issue with the selected vs active option

There could be. So, what does the selected option do?

There could be. So, what does the selected option do?

Hoped you would know 😅 , but anyhow I will give this a more in dept check then 👍 From a quick check seems like two different icon modes one for when the icon is clicked or hovered and the other when is actually selectable/selected 🤔

Hoped you would know 😅

Haha, sorry, no idea!

commented

Hi @dalthviz and @ccordoba12!

Big thank you for a quick response 😃

Okay, so I thought that "selected" for an icon means the same as "checked" for a button. So if the button is setCheckable(True), setAutoExclusive(True) and it is checked it means that the icon will be in "selected" mode and will show icon of the state.

Under "selected" mode I understand that if for example we have two groups of buttons and basicaly they are working like a radio buttons (setCheckable(True) and setAutoExclusive(True) - only one button of the group can be selected). 😵 So, if we push one button of a first group it will be selected all the time till next button of the group will be selected instead of.

I am thinking that "Active" works differently. I am not sure and please correct me if I am wrong but I think that "active" mode keeps the icon active all the time till another object will be clicked anywhere. 😅

Please look at below gifs:

toggle_icon = qta.icon('ph.house', active='ph.check-square',
                                    color_off='black',
                                    color_off_active='blue',
                                    color_on='orange',
                                    color_on_active='green')
toggle_button = QPushButton(parent=parent, icon=toggle_icon, text=btn + ' Toggle')
toggle_button.setAutoExclusive(True)
toggle_button.setCheckable(True)
  • on the left with 'active' in kwords - the icon is changing correctly but if I press another button out of the group the icon go back to default
  • on the right with 'selected' in kwords - currently changing icon is not working at all

active                selected

Thanks for the feedback and testing @r-bash ! Seems more and more to me that we have an issue here with the selected option. In case you would like to give it a try and debug what could be happening, I think the related code that parses the options is here:

parsed_options = []
for i in range(len(options_list)):
specific_options = options_list[i]
parsed_options.append(self._parse_options(specific_options,
general_options,
names[i]))
# Process high level API
api_options = parsed_options
self.icon_cache[cache_key] = self._icon_by_painter(self.painter, api_options)