qml中,怎么给Rectangle设置鼠标移入变色,移除恢复?
Button怎么去掉边框? Button怎么改变背景色?

qml中,怎么给Rectangle设置鼠标移入变色,移除恢复?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- qtchen_1988 2019-07-24 15:02关注
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" //点击更改颜色 } } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报