PDA

View Full Version : How do i style a toplevel widget?



Nyte
15th August 2017, 10:25
This is an issue I'm having trouble with for a long time, and usually have a workaround for, but at this time... i can no longer use my workaround.

How do i style a top level widget

I have a .ui file with 2 objects.:



QWidget (MyQWidget)

QListWidget (MyQListWidget)



In my .css file, I just cannot style the QWidget. Say with a simple border or background. Here's what i experimented.


* {border: 1px solid red}
Works, but obviously gives everything else a border as well


QWidget {border: 1px solid red}
Works, but gives every QWidget a border as well


#MyQWidget {border: 1px solid red}
Doesn't work


QWidget #MyQWidget {border: 1px solid red}
Doesn't work


QWidget > #MyQWidget {border: 1px solid red}
Doesn't work


#MyQWidget QWidget {border: 1px solid red}
Doesn't work


My usual workaround was just to add another QFrame and give it no margins. Anything below the Toplevel widget i can easily style, but not the top-widget itself.
Can anyone please educate me how to properly style the topwidget?

Ginsengelf
15th August 2017, 15:23
#MyQWidget {border: 1px solid red}
This works for me, at least with a minimal example in Designer with Qt 5.8.

Ginsengelf