PDA

View Full Version : MainWindow Background-Image issues



BingoMaster
23rd October 2009, 17:58
I have a MainWindow with a StyleSheet:


background-image: url(:/Images/DefaultBackground);

My issue is all the widgets on the MainWindow are now using this background instead of their own StyleSheet.

Also the QLabel are no longer transparent because of the background image.

What am I doing wrong?

BingoMaster
23rd October 2009, 18:38
Found my answer:

It appears that when using a stylesheet at the lowest level all widgets inherit that stylesheet also. (If I am wrong please let me know)



QMainWindow {
background-image: url(:/Images/DefaultBackground);
}

Erik_Klein
5th November 2009, 18:22
hey, thats true. I guess when you say "lowest level" you mean the top-level layer. The stylesheet follows a cascading principle, so if you apply style to something at top-level it will inherit in most objects which are within that layer. One way to get aroun that is for example apply the styling specific to a object, so for instance if your QMainWindow was callled "Alpha" and you wanted to style the background only to this main window you could say...

#alpha {
background-image: url(:/Images/DefaultBackground);
}

instead of....

QMainWindow {
background-image: url(:/Images/DefaultBackground);
}

the benefit of the first example is that if you have various similar widgets, but you only want to style one of those, this will only apply to the one with that object name.