如何创建具有多种颜色的qt QTButton?

时间:2021-04-28 21:04:07

标签: qt qt5 qt5.6

我正在寻找如何在背景颜色中创建具有多种颜色的 QT 按钮。

按钮应该是这样的

enter image description here

1 个答案:

答案 0 :(得分:2)

使用渐变:

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