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. Setting QLinearGradient with Stylesheet always shows Black
Qt 6.11 is out! See what's new in the release blog

Setting QLinearGradient with Stylesheet always shows Black

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 8.7k Views
  • 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.
  • Fuel 0F Offline
    Fuel 0F Offline
    Fuel 0
    wrote on last edited by
    #1

    i have a new Project with Qt 5.9.5 on Linux. Everything is very new, except the Linux Installation. In the Project i want to use a Gradient for a QToolBar, but everything i tried doesnt work. When i set a normal Color with "background-color: blue;" then it works. But every LinearGradient Option shows always a Black Background.

    Normally i use the set Stylesheet Option from QT Creator, but i also tried it with ->setStyleSheet() in Code.

    This is what i have now.

    QToolBar {
    	background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1,stop: 0 white, stop: 0.4 gray,stop: 1 green);
    }
    
    DiracsbracketD 1 Reply Last reply
    0
    • Fuel 0F Fuel 0

      i have a new Project with Qt 5.9.5 on Linux. Everything is very new, except the Linux Installation. In the Project i want to use a Gradient for a QToolBar, but everything i tried doesnt work. When i set a normal Color with "background-color: blue;" then it works. But every LinearGradient Option shows always a Black Background.

      Normally i use the set Stylesheet Option from QT Creator, but i also tried it with ->setStyleSheet() in Code.

      This is what i have now.

      QToolBar {
      	background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1,stop: 0 white, stop: 0.4 gray,stop: 1 green);
      }
      
      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @Fuel-0
      Hi. I tried your gradient on my toolbar (although I am testing it on Win10, Qt 5.10.1), and it seems to work correctly.

          ui->mainToolBar->setStyleSheet("QToolBar {\
          background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1,stop: 0 white, stop: 0.4 gray,stop: 1 green);}");
      

      0_1525575562160_5fefaf15-d71c-404f-9417-b9a12528c634-image.png

      Do other uses of gradient work on your system? e.g. the Qt example
      https://doc.qt.io/qt-5.10/qtwidgets-painting-gradients-example.html

      1 Reply Last reply
      1
      • Fuel 0F Offline
        Fuel 0F Offline
        Fuel 0
        wrote on last edited by
        #3

        i dont know why it works now, but i dont use the Designer now. I created my QToolBar in the Source and use setStyleSheet().

        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