Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Stylesheets for widget background
Forum Updated to NodeBB v4.3 + New Features

Stylesheets for widget background

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mirswith
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mirswith
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved