如何更改“Qt Quick - Control 2圆形按钮”的颜色

3

有人知道如何更改 Qt Controls 2.1 中的控件“RoundButton”的颜色吗?

我尝试更改背景,但如果我将“Rectangle”放在项目中,RoundButton就会变成矩形,我不知道该放什么。

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

    text: "ah"
    wheelEnabled: false

    background: Rectangle {
        color: "yellow"
        height: 50
        width: 50
    }
}
2个回答

7
使用Qt 5.10,您可以使用调色板属性来避免覆盖背景的需要:
import QtQuick 2.9
import QtQuick.Controls 2.3

ApplicationWindow {
    visible: true

    RoundButton {
        id: button
        text: "ah"

        palette.button: "salmon"
    }
}

目前并非所有样式都支持调色板属性:默认和融合样式支持,Imagine样式也支持(大部分是文本颜色,因为它是基于图像的样式)。
如果您想知道特定样式要使用哪个调色板角色,最简单的方法可能是查看源代码。

http://code.qt.io/cgit/qt/qtquickcontrols2.git/tree/src/imports/controls/Button.qml#n77

尽管角色列表已记录:

https://doc.qt.io/qt-5.10/qml-palette.html#qtquickcontrols2-palette


0

你应该使用radius

roundButton只是一个带有radius属性设置为360的Button如此处所述), 因此在你的示例中它将是:

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

    text: "ah"
    wheelEnabled: false

    background: Rectangle {
        color: "yellow"
        implicitHeight: 50
        implicitWidth: 50
       radius: 360
    }
}


请注意,这样做基本上是没有用的,因为您可以使用一个Button并将半径设置为360,它会是相同的...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接