Last active
March 16, 2017 13:04
-
-
Save tbnorth/76191db825cc49dcca296ffb8d777047 to your computer and use it in GitHub Desktop.
Demo Qt 5.8 stylesheet tilde problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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