Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting QLinearGradient with Stylesheet always shows Black



  • 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);
    }
    


  • @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



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


Log in to reply