Important: Please read the Qt Code of Conduct -

Background image question

  • I'm a Qt newbie, so maybe this is a dumb question...

    In QtDesigner, I set the centralWidget styleSheet propery to:

    border-image: url(:/QtOub/LogonBackground.jpg) 0 0 0 0 stretch stretch

    Then I added a groupbox the centralWidget with a few buttons and stuff.

    To my surprise, each widget (including the groupBox and each of its subwidgets) all have the image as their background.

    Ok, so apparently it "inherits" the background image from the centralWidget.

    So I set the groupBox's styleSheet property to "background-color: grey" thinking that it would clear the image to get a a plain grey backround for the groupBox. But I still see the images!

    Can someone explain what's going on and how to fix it?

  • that's why they are called cascading style sheets

    what you need to do is call setObjectName on the central widget to give it a unique name (say MyCentralWidget) and then set the stylesheet to

    #MyCentralWidget{border-image: url(:/QtOub/LogonBackground.jpg) 0 0 0 0 stretch stretch;}

  • Thanks, that did the trick!

Log in to reply