Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Last active March 16, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbnorth/76191db825cc49dcca296ffb8d777047 to your computer and use it in GitHub Desktop.
Save tbnorth/76191db825cc49dcca296ffb8d777047 to your computer and use it in GitHub Desktop.
Demo Qt 5.8 stylesheet tilde problem
"""
Qt >= 5.8 stops parsing stylesheet when it sees ~=,
button text is underlined but not italic, and doesn't change when clicked
PyQt < 5.8 works as expected, button text is underlined and italic,
and becomes large and red when clicked
"""
import sys
from PyQt5 import QtWidgets
SHEET = """
QPushButton {text-decoration: underline;}
QWidget[style_class ~= 'large'] {font-size: 48px;}
QWidget[style_class ~= 'urgent'] {color: red;}
QPushButton {font-style: italic;}
"""
def main():
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
window.setStyleSheet(SHEET)
button = QtWidgets.QPushButton("Button")
def callback(clicked, button=button):
button.setProperty('style_class', 'urgent active large etc')
button.setStyleSheet("/* */") # force update of widget styling
button.clicked.connect(callback)
window.setCentralWidget(button)
window.show()
app.exec_()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment