Search code examples
qtqt5qt5.6

how to create a qt QTButton with multiple colors?


I am looking for how to create a QT button with multiple color in background color.

Button should look like this

enter image description here


Solution

  • Use a gradient:

    button->setStyleSheet(R"(
        background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 0, 102, 255), stop:0.55 rgba(0, 148, 61, 255), stop:0.98 rgba(0, 255, 0, 255), stop:1 rgba(0, 0, 0, 0));
        border-radius:  10px;
    )");
    

    enter image description here