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.

Qt Code:
  1. * {border: 1px solid red}
To copy to clipboard, switch view to plain text mode 
Works, but obviously gives everything else a border as well

Qt Code:
  1. QWidget {border: 1px solid red}
To copy to clipboard, switch view to plain text mode 
Works, but gives every QWidget a border as well

Qt Code:
  1. #MyQWidget {border: 1px solid red}
To copy to clipboard, switch view to plain text mode 
Doesn't work

Qt Code:
  1. QWidget #MyQWidget {border: 1px solid red}
To copy to clipboard, switch view to plain text mode 
Doesn't work

Qt Code:
  1. QWidget > #MyQWidget {border: 1px solid red}
To copy to clipboard, switch view to plain text mode 
Doesn't work

Qt Code:
  1. #MyQWidget QWidget {border: 1px solid red}
To copy to clipboard, switch view to plain text mode 
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?