qml中,怎么给Rectangle设置鼠标移入变色,移除恢复?
Button怎么去掉边框? Button怎么改变背景色?
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
import QtQuick.Controls.Private 1.0
Rectangle {
id:root
width: 800
height: 480
color: "green"
function mouseEnter(flag){ //处理鼠标进入或者移出变色
child.color = flag? "cyan":"darkGray"
}
Rectangle {
id: child
anchors.centerIn: parent
width: 300
height: 200
color: "darkGray"
MouseArea {
id: mouseId
anchors.fill: parent
hoverEnabled: true
onEntered: { //监听鼠标进入
mouseEnter(true);
//console.log("#### Entered #####")
}
onExited: { //监听鼠标移出
mouseEnter(false);
//console.log("#### Exited #####")
}
}
}
Button{
id: button
width: 100
height: 30
x: child.x + child.width + 10
anchors.bottom: child.bottom
style: ButtonStyle {
background: Rectangle {
border.color: "transparent"//去掉边框
color: control.pressed ? "#CD0000":"#CD00CD" //点击更改颜色
}
}
}
}