单击按钮打开另一个 QML 窗口时,我需要隐藏 QML 窗口,我使用 Loader 打开另一个 QML 窗口,它只隐藏 QML 表单组件而不是 QML 窗口,但我目前使用窗口组件打开 QML 窗口
这是我的代码:
Button {
id: button2
x: 19
y: 54
width: 114
height: 25
text: qsTr("DIFF-R")
style: ButtonStyle {
background: Rectangle {
implicitWidth: 10
implicitHeight: 25
border.width: control.activeFocus ? 2 : 1
border.color: "#555"
radius: 10
gradient: Gradient {
GradientStop { position: 0 ; color: control.pressed ? "#ddd" : "#fff" }
GradientStop { position: 1 ; color: control.pressed ? "#8ad993" : "#528dc8" }
}
}
} …Run Code Online (Sandbox Code Playgroud) Button我需要更改按下时的背景图像。如果在按下之前有背景图像Button,则需要在按下时更改该背景图像,然后在释放Button时将其设置回原始背景图像。Button
这是我当前的代码:
property bool bImgChange: true
Button {
id: bu
x: 121
y: 40
iconSource: "q.png"
activeFocusOnPress: false
opacity: 1
checkable: true
checked: true
Layout.minimumWidth: 100
Layout.minimumHeight: 100
onClicked: {
if ( bImgChange == true )
{
bu.iconSource = "index.png"
bImgChange = false
}
else
{
bu.iconSource = "q.png"
bImgChange = true
}
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码仅在Button单击时设置背景图像,而我需要在按下和释放时更改背景图像。