Important: Please read the Qt Code of Conduct -

Stylesheet breaks QPushButton pressed on macOS

  • PySide2 5.15.0
    Python 3.7.6
    macOS 10.15.5

    I'm not sure if this is a bug, but my app's QPushButtons that are styled with CSS style sheets aren't functional on macOS. The CSS seems to break the button's ability to call the clicked signal. Everything was working fine last time I tested it on mac about a month ago, and it works fine on a PC, so I'm not sure what could have changed. Is there a more stable version of PySide2 that I should be targeting? Has something changed on the mac end?

    I did about a weeks. worth of digging prior to writing this and found that the stylesheets seem to be the issue. Just changing the color and bg color breaks the buttons. Removing the style sheet brings back normal functionality. If I want styled buttons to work I have to set values for height, border-radius, and margin for each state. Even then the button has dead areas that don't work, so this isn't a real fix.

    Here's an example of code that breaks the buttons. The default and hover states work but clicks never register:

    import sys
    from PySide2 import QtWidgets
    class Example(QtWidgets.QWidget):
    	def __init__(self):
    		super(Example, self).__init__()
    	def initUI(self):
    		btn1 = QtWidgets.QPushButton("Button 1", self)
    			background-color: #00000000;
    			color: #9E9E9E;
    			color: #FFFFFF;
    			background-color: #5a5a5a;
    			color: #9c2219;
    			color: #2c998e;
    		btn1.move(30, 50)
    		btn2 = QtWidgets.QPushButton("Button 2", self)
    		btn2.move(150, 50)
    		# self.statusBar()
    		self.setGeometry(300, 300, 290, 150)
    		self.setWindowTitle('Event sender')
    	def buttonClicked(self):
    def main():
    	app = QtWidgets.QApplication(sys.argv)
    	ex = Example()
    if __name__ == '__main__':

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you check with a previous version of PySide2 ?

  • Thanks!

    Just tried PySide2 and it works! Is this a bug?

  • @borbs727
    Yes :) If it's reproducible for others.

  • Lifetime Qt Champion

    You may have found a regression.

    You should check the bug report system to see if there's something related.

  • I can confirm the same thing happens with Qt/C++ on MacOS. Once I style my buttons, they cannot be clicked anymore. Just a simple background-color: #404040 is enough.

  • @chris_mndcr , @SGaist
    I don't know which person reported this recently, but I see two reports for this:

  • @JonB said in Stylesheet breaks QPushButton pressed on macOS:

    ah, thank's alot! good to see it was already fixed

Log in to reply