qt - 更改 QML 的 RadioButton 中文本的颜色

标签 qt qml

使用Qt Quick Controls 1,有没有办法改变QML中RadioButton的文本颜色?

我想将其更改为白色,因为我的背景是黑色,找不到方法。

qml

                RowLayout {
                    RadioButton {
                        width:15
                        height:15
                        text: "xlsx"
                        checked: true
                    }
                    RadioButton {
                        width:15
                        height:15
                        text: "Bottom"
                    }
                }

最佳答案

对于 Qt Quick Controls 2,您应该使用自定义 contentItem 创建自己的 RadioButton 组件:

RadioButton {
    id: control
    width: 15
    height: 15
    text: "xlsx"
    contentItem: Text {
        text: control.text
        color: "white"
        leftPadding: control.indicator.width + control.spacing
        verticalAlignment: Text.AlignVCenter
    }
}

请参阅文档中的完整示例:Customizing RadioButton .

对于 Qt Quick Controls 1,请参阅 @Roya Ghasemzadeh 的回答。

关于qt - 更改 QML 的 RadioButton 中文本的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56111419/

相关文章:

c++ - 如何在qt中不用鼠标点击就可以平移图像

c++ - Qt ListView 不显示 C++ 模型内容

qt - QListView如何添加列?

c++ - 从 C++ Qt 5.2.1 更改 QML 文本框中的文本

c++ - QML 可以看到我的 Q_GADGET 但看不到 Q_OBJECT

c++ - 如何将原生窗口嵌入到 QML 组件中?

python - QImage : URL instead of file path?

python - 当模型增长时,让 QTableView 滚动到最后一行

rust - Cargo 无法在 Windows 10 上编译 rust-qml

c++ - 在 QML 中显示 FPS