【问题标题】:How change the color of "Qt Quick - Control 2 RoundButton"如何更改“Qt Quick - Control 2 RoundButton”的颜色
【发布时间】:2018-01-17 13:51:33
【问题描述】:

任何人都知道如何更改控件“RoundButton”的颜色,该控件从 2.1 开始就出现在 Qt Controls 中。

我尝试更改背景,但如果我将“矩形”放在项目上,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 qml qtquickcontrols2


    【解决方案1】:

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

    import QtQuick 2.9
    import QtQuick.Controls 2.3
    
    ApplicationWindow {
        visible: true
    
        RoundButton {
            id: button
            text: "ah"
    
            palette.button: "salmon"
        }
    }
    

    虽然目前并非所有样式都尊重调色板属性:Default 和 Fusion 样式都可以,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

    【讨论】:

      猜你喜欢
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      相关资源
      最近更新 更多