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");
    layout->addWidget(label);
    layout->addStretch(1);
    setLayout(layout);

    setStyleSheet("QWidget{"
    "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?

    Thanks.



  • Found the answer to my own question, looks like I have to override the paintEvent as per the docs here "stylesheet reference":http://qt-project.org/doc/qt-4.8/stylesheet-reference.html

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

    I'm half way there. :)

    Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.