Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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__()
    
    		self.initUI()
    
    	def initUI(self):
    		btn1 = QtWidgets.QPushButton("Button 1", self)
    		self.setStyleSheet("""
    		QPushButton{
    			background-color: #00000000;
    			color: #9E9E9E;
    		}
    		QPushButton:hover{
    			color: #FFFFFF;
    			background-color: #5a5a5a;
    		}
    		QPushButton:pressed{
    			color: #9c2219;
    		}
    		QPushButton:checked{
    			color: #2c998e;
    		}
    		""")
    		btn1.move(30, 50)
    
    		btn2 = QtWidgets.QPushButton("Button 2", self)
    		btn2.move(150, 50)
    
    		btn1.clicked.connect(self.buttonClicked)
    		btn2.clicked.connect(self.buttonClicked)
    
    		# self.statusBar()
    
    		self.setGeometry(300, 300, 290, 150)
    		self.setWindowTitle('Event sender')
    		self.show()
    
    	def buttonClicked(self):
    		print('clicked')
    
    
    def main():
    	app = QtWidgets.QApplication(sys.argv)
    	ex = Example()
    	sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
    	main()
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you check with a previous version of PySide2 ?



  • Thanks!

    Just tried PySide2 5.14.2.2 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:
    https://bugreports.qt.io/browse/QTBUG-84493
    https://bugreports.qt.io/browse/QTBUG-84879



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

    https://bugreports.qt.io/browse/QTBUG-84879

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


Log in to reply