qq_43186704
八条腿不敲代码
采纳率100%
2019-07-24 13:55

qml中,怎么给Rectangle设置鼠标移入变色,移除恢复?

已采纳

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • qtchen_1988 qtchen_1988 2年前
    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" //点击更改颜色
                 }
             }
         }
    }
    
    点赞 评论 复制链接分享

相关推荐