![](/img/trans.png)
[英]How to change the background color of a QML Button Qt Quick Controls 2?
[英]How change the color of “Qt Quick - Control 2 RoundButton”
任何人都知道如何改變控件“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 5.10,您可以使用palette屬性來避免必須覆蓋背景:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.