Important: Please read the Qt Code of Conduct -

Stylesheets for widget background

  • I am trying to set the background for a widget using a gradient however it appears only the child widgets of my widget are getting the background. For testing in my widget constructor I have something like this:

    QVBoxLayout * layout = new QVBoxLayout();
    QLabel * label = new QLabel("test");

    "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #565656, stop:1 #383838);"

    What this does is put a gradient on my label but instead I want it to fill myself then further I do not want my child widgets to inherit this style. How would I go about doing this?


  • Found the answer to my own question, looks like I have to override the paintEvent as per the docs here "stylesheet reference":

    Is there a way to set the style sheet for only myself and not my child widgets?

    I'm half way there. :)


Log in to reply