Important: Please read the Qt Code of Conduct -

Best way to use "change styleSheet..." in Qt Designer?

  • Hi,

    I've been using the "change styleSheet.." feature in Qt Designer (by right-clicking on a widget) to change the background of QDialogs and tab pages; inserting, for example,

    #<widget name> {
    background-color: white;

    however I find that setting the stylesheet appears to damage the style used by some child widgets within the dialogs. For example in QTableViews it resets vertical and horizontal header font sizes to be the same as the cell text font size, when it should be smaller.

    (If I change the background color in code, by modifying each widget's palette, the problems don't occur.)

    Does anyone know the correct syntax for setting stylesheet items in Qt Designer without damaging child widgets?

    The current behaviour seems to make the "Change styleSheet..." feature in Qt Designer useless...


  • Lifetime Qt Champion

    Stylesheets are cascading by nature so they will affect child widgets if the selector matches,
    The best way to control it is by using one stylesheet on the application. and never used
    broad selectors like QWidget unless you really mean it.

    While developing the stylesheet i set it on the MainWindow as its top parent and own most of the widgets.

  • @mrjj Makes sense. But what I'm asking is how to properly set the properties I care about, without damaging or clearing other properties.

  • Lifetime Qt Champion

    well if you put a style sheet on a Widget, it disables the normal drawing so you have to style it fully.
    But can you give an example of something that goes wrong ?

  • @mrjj There's an example in the OP above.

  • Lifetime Qt Champion

    if you use good selectors, it should
    only affect the widgets you target.

Log in to reply