如何更改“的颜色”;Qt快速-控制2圆形按钮“;

如何更改“的颜色”;Qt快速-控制2圆形按钮“;,qt,qml,qtquickcontrols2,Qt,Qml,Qtquickcontrols2,任何人都知道我如何改变控件“RoundButton”的颜色,从2.1开始,Qt控件中就出现了这种颜色 我试着改变背景,但如果我把“矩形”放在项目上,RoundButton就会变成矩形,我不知道该放什么 RoundButton { id: roundButton x: 243 y: 244 width: 20 height: 20 text: "ah" wheelEnabled: false background: Rectang

任何人都知道我如何改变控件“RoundButton”的颜色,从2.1开始,Qt控件中就出现了这种颜色

我试着改变背景,但如果我把“矩形”放在项目上,RoundButton就会变成矩形,我不知道该放什么

RoundButton {
    id: roundButton
    x: 243
    y: 244
    width: 20
    height: 20

    text: "ah"
    wheelEnabled: false

    background: Rectangle {
        color: "yellow"
        height: 50
        width: 50
    }
}

使用Qt 5.10,您可以使用调色板属性来避免覆盖背景:

import QtQuick 2.9
import QtQuick.Controls 2.3

ApplicationWindow {
    visible: true

    RoundButton {
        id: button
        text: "ah"

        palette.button: "salmon"
    }
}
不过,目前并非所有样式都尊重调色板属性:默认样式和融合样式以及想象样式尽可能尊重调色板属性(主要是文本颜色,因为它是基于图像的样式)

如果您想知道在特定样式中使用哪个调色板角色,可能最容易查找源代码:

虽然已记录了角色列表: