pyqt6: Set CSS - I need help
-
Hello,
I've tried everything imaginable, I don't understand it.here is my code:
def set_style(self, font_size=None, high_contrast=False): style = '' if font_size: style = f'font-size: {font_size}px;' self.setStyleSheet(style) # Stattdessen `self.setStyleSheet` if high_contrast: app_css = """QPushButton:focus { background-color: yellow } QTextEdit:focus { background-color: yellow } QComboBox:focus { background-color: yellow } QMainWindow {background-color: black; color: white;}""" self.setStyleSheet(style)
If the user just wants to change the font size, it works.
But as soon as I want to change the font size and the background color and font color of the app, the program crashes.
Ask:
How does it work? -
@PythonQTMarlem
It does not help that you open a new topic for this when you already have one for the same on-going. And there you do not answer questions posed to you. For example, I asked you there what theself
is you keep using to set the stylesheet on but you ignored it. If we don't know that it's hard to begin to answer what is going on.If your program actually "crashes", run it under debugger and show us the error and the stack trace.
The code you show does not set all the color stuff since you assign the string to
app_css
variable and do not use that.When you do use it, can you please append a
;
each place afteryellow
. I don't know if it's compulsory there, but if you are having problems why don't you at least eliminate that? -
Hello,
At first I thought I had a problem with the menu. Now I've come to the conclusion that it's the CSS. There are no error messages at the moment, but here is debug information as requested:app_css = {str} 'QPushButton:focus { background-color: yellow } QTextEdit:focus { background-color: yellow } QComboBox:focus { background-color: yellow } QMainWindow {background-color: black; color: white;}'
font_size = {str} '30'
high_contrast = {bool} True
self = {HTMLGeneratorApp} <main.HTMLGeneratorApp object at 0x0000026E98A09EA0>
style = {str} 'font-size: 30px;'