How change the color of “Qt Quick - Control 2 RoundButton”

ⅰ亾dé卋堺 提交于 2019-12-07 12:42:44

问题


Anybody know how I can change the color of the control "RoundButton", present in the present in Qt Controls since 2.1.

I tried changing the background, but if I put "Rectangle" at the item the RoundButton became rectangular and I don't know what to put instead.

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

    text: "ah"
    wheelEnabled: false

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

回答1:


With Qt 5.10 you can use the palette property to avoid having to override the background:

import QtQuick 2.9
import QtQuick.Controls 2.3

ApplicationWindow {
    visible: true

    RoundButton {
        id: button
        text: "ah"

        palette.button: "salmon"
    }
}

Not all styles currently respect the palette property though: the Default and Fusion styles do, and the Imagine style does, where it can (mostly text colours, as it's an image-based style).

If you're curious which palette role to use for a particular style, it's probably easiest to look to the source code:

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

Although the list of roles is documented:

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



来源:https://stackoverflow.com/questions/48302755/how-change-the-color-of-qt-quick-control-2-roundbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!