MAYA 2018 PyQt Changing PushButton Icon when clicked - How?



Hi Guys! I’m new to this community and to programming in python at all, so don’t judge me for stupid questions :slight_smile:

I’m trying to create one script for Maya and which will use similar functionality to PS layers visibility with eye icon.
So basically I’m using QPushButton class with icon. And I want to change this eye icon when button is clicked.
I’m using two icons (opened eye and closed eye) and function to connect button.setIcon(), but I can’t find what state or flag should I use to query which icon is used.
Here is my code :

self.eyeicon_1 = QtGui.QIcon(os.path.join(ROOT, “icons”, “vis.svg”))
self.eyeicon_2 = QtGui.QIcon(os.path.join(ROOT, “icons”, “invis.svg”))


def eyeChanged():
if self.visButton.????() == self.eyeicon_1:
elif self.visButton.????() == self.eyeicon_2:

Could you please help me to find a solution?


Hey, are you sure you’re not looking for a checkbox widget then?

As a minimal example

import sys
from PySide2 import QtWidgets
from PySide2 import QtCore

app = QtWidgets.QApplication(sys.argv)
checkbox = QtWidgets.QCheckBox()
    "QCheckBox::indicator:checked {image: url(.//res//checked.png);}"
    "QCheckBox::indicator:unchecked {image: url(.//res//error.png);}"

This is a QCheckBox that uses Stylesheets to set the indicator.

Using your preexisting code, you’re probably looking to check self.visButton.icon()


Hi, thank you for your answer.
I’ve tried to use self.visButton.icon() , but somehow it doesn’t work… It should actually, but doesn’t. And I don’t know why.

Probably I’ll try to use checkbox solution.


Hi, I’ve decided to use CSS style sheet and it only works if I write direct path to my images (like C:/projects/… ).
But I don’t know how to use my working root directory {image: url(???//res//checked.png);}

If you could help me how to set up my working root directory, that would be great!


So basically I need to understand how Maya’s PySide treats CSS style current directory


My example used relative paths. Single dot should be current dir. Just like relative import in python is done.

The structure for my example was