Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selected option doesn't change QPushButton icon only icon color #237

Open
r-bash opened this issue Jun 19, 2023 · 6 comments
Open

Selected option doesn't change QPushButton icon only icon color #237

r-bash opened this issue Jun 19, 2023 · 6 comments

Comments

@r-bash
Copy link

r-bash commented Jun 19, 2023

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

@dalthviz
Copy link
Member

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 ?

@dalthviz dalthviz added this to the v1.3.0 milestone Jun 21, 2023
@ccordoba12
Copy link
Member

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?

@dalthviz
Copy link
Member

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 🤔

@ccordoba12
Copy link
Member

Hoped you would know 😅

Haha, sorry, no idea!

@r-bash
Copy link
Author

r-bash commented Jun 23, 2023

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

@dalthviz dalthviz removed the docs label Jun 23, 2023
@dalthviz
Copy link
Member

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)

@dalthviz dalthviz changed the title QIcon:Selected Selected option doesn't change QPushButton icon only icon color Jun 23, 2023
@dalthviz dalthviz modified the milestones: v1.3.0, v1.4.0 Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants