qml定制菜单栏与Win关闭按钮产生一样的效果

qml定制菜单栏与Win关闭按钮产生一样的效果

win关闭按钮鼠标悬浮时是红色的背景,这种效果怎么产生的呢,请看下面的代码实现

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("定制标题栏")


    //color: "transparent"
    flags: Qt.Window | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint | Qt.FramelessWindowHint

    //关闭按钮
    MouseArea{
        id: imgWinClose
        hoverEnabled: true
        cursorShape: Qt.PointingHandCursor
        anchors.top: parent.top
        anchors.right: parent.right
        width: 24
        height: 24

        Rectangle{
            anchors.fill: parent
            color: parent.containsMouse ? "#FF3E3D" : "#00000000"
        }

        Image{
            z: 1
            anchors.centerIn: parent
            sourceSize.width: 24
            sourceSize.height: 24
            source: parent.containsMouse ? "qrc:/image/icon_close.svg" : "qrc:/image/icon_close.svg"
        }

        onClicked: {
            console.log("close window================")
            close()
        }
    }

    //最大化按钮
    MouseArea{
        id: imgWinMax
        hoverEnabled: true
        cursorShape: Qt.PointingHandCursor
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.rightMargin: 24
        width: 24
        height: 24

        Rectangle{
            anchors.fill: parent
            color: parent.containsMouse ? "#CFD2DC" : "#00000000"
        }

        Image{
            z: 1
            anchors.centerIn: parent
            sourceSize.width: 24
            sourceSize.height: 24
            source: parent.containsMouse ? "qrc:/image/icon_max.svg" : "qrc:/image/icon_max.svg"
        }

        onClicked: {
            console.log("max window================")
            showMaximized()
        }
    }

    //最小化按钮
    MouseArea{
        id: imgWinMini
        hoverEnabled: true
        cursorShape: Qt.PointingHandCursor
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.rightMargin: 48
        width: 24
        height: 24

        Rectangle{
            anchors.fill: parent
            color: parent.containsMouse ? "#CFD2DC" : "#00000000"
        }

        Image{
            z: 1
            anchors.centerIn: parent
            sourceSize.width: 24
            sourceSize.height: 24
            source: parent.containsMouse ? "qrc:/image/iocn_mini.svg" : "qrc:/image/iocn_mini.svg"
        }

        onClicked: {
            console.log("max window================")
            showMinimized()
        }
    }

}

运行效果

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值