I have an application that writes its own stylesheet, based off user input. It changes the back-ground colours / images of indiviual widgets via user selection.
Whenever I begin using this feature, everything works perfect. However, eventually things grind to a halt. No visual changes are made to the window, even though the stylesheet is continually being added to and set onto the application.
Since there is some strong string manipulation involved in generating the CSS, my guess is that there is some error in the CSS that is stopping Qt from interpreting all of it.
I cannot spot this error! My CSS is always in the format of
"#widget { 'correctly formatted properties';} #nextwidget..."
I know for a fact (by the limits of the algorithm and by checking the broken CSS files), that the properties set to each widget are syntactically correct.
I notice that doing this however…
#widget {color: ;}
… does not stop Qt from interpreting the rest of the string, but using non-existing properties (eg: { goose: 2 } ) does.
So, what kind of errors are dismissed by Qt, and what stops the interpretation of the rest of the file? I couldn’t find a list or anything of the sort in the Qt documentation.
(In fact, there’s not even any stylesheet documentation in the PyQt4 package.)
In the case of my CSS, I apply…
{color: x; background-image:, y, background-color: z }
to every single widget the User selects (with x,y,z being correct subsitutions).
Are there any visible widgets that don’t support these properties?
(which could be the source of my problem!)
I tried putting the SS in a Validator and here are two CSS fragments that caused error, of which I don’t know why!
#centralwidget { color: #ffffff ;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #aaff00, stop: 1 #aac300)
}
and…
#Display { background-image: url('+NewTextureFile+');
background-repeat: repeat-xy;
}
If anybody could help with these too, I’d be extremely appreciative!
(It’s probably obvious I’ve been improving my way into CSS…)
EDIT:
@ Avaris:
Sorry this broken CSS is not minimal; I don’t know what part is broken!
I have a suspicion that it’s because I don’t finish all properties with ‘;’.
#tab{color: #000000 ;background-color: #ff0000 } #tab{color: #000000 ;background-image: url(E:/ChemCalc ULTIMATE/ChemCalc ULTIMATE/Texture Files/Penguins.jpg);background-repeat: repeat-xy; } #Amount_Unit{color: #000000 ;background-color: #aaff00 } #Conc_Unit2{color: #000000 ;background-color: #aaff00 } #pushButton{color: #000000 ;background-color: #aaff00 } #tab_2{color: #000000 ;background-image: url(E:/ChemCalc ULTIMATE/ChemCalc ULTIMATE/Texture Files/Penguins.jpg);background-repeat: repeat-xy; } #RMM_Output{color: #000000 ;background-color: #aaff00 } #Conc_Unit1{color: #000000 ;background-color: #aaff00 } #UnitText{color: #000000 ;; } #Amount_Input{color: #000000 ;; } #Concentration_Input{color: #000000 ;; } #Amount_Output{color: #000000 ;; } #Subshell_Element{color: #000000 ;background-color: #00aaff } #Charge{color: #000000 ;background-color: #00aaff } #Simple_Config{color: #000000 ;background-color: #00aaff } #Actual_Config{color: #000000 ;background-color: #00aaff } #Save_Simple_Button{color: #ffffff ;background-color: #aaff00 } #Save_Actual_Button{color: #ffffff ;background-color: #aaff00 } #pushButton_2{color: #ffffff ;background-color: #aaff00 } #centralwidget{color: #ffffff ;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #aaff00, stop: 1 #aac300) } #pushButton_3{color: #000000 ;background-color: #ff0000 } #Calculate_Proportions_Button{color: #000000 ;background-color: #f80000 } #{color: #000000 ;background-image: url(E:/ChemCalc ULTIMATE/ChemCalc ULTIMATE/Texture Files/Koala.jpg);background-repeat: repeat-xy; } #tab_4{color: #000000 ;background-image: url(E:/ChemCalc ULTIMATE/ChemCalc ULTIMATE/Texture Files/Koala.jpg);background-repeat: repeat-xy; } #LayoutContainer1{color: #000000 ;background-image: url(E:/ChemCalc ULTIMATE/ChemCalc ULTIMATE/Texture Files/Koala.jpg);background-repeat: repeat-xy; } #AmountInput{color: #ffaa00 ;background-color: #ffff00 } #tab_5{color: #000000 ;background-color: #ffffff } #menubar{color: #000000 ;background-color: #ffffff } #tabWidget{color: #000000 ;background-color: #ffffff } #Reaction_Element_Holder{color: #000000 ;background-image: url(E:/ChemCalc ULTIMATE/ChemCalc ULTIMATE/Texture Files/Penguins.jpg);background-repeat: repeat-xy; }
Thanks for reading!
PyQt4
python 2.7.2
Windows 7
Looking at the example CSS, there is an
IDselector without a name:which threw the parser and made the rest of CSS after that point invalid.
As a side point, nameless
IDselector is in fact invalid CSS. W3C Validator gives:for:
But browsers I tested (Opera, Firefox) was smart enough to ignore and continue. Apparently Qt CSS parser is not comfortable with this kind of errors.