Qml类似QQ登录界面设置时的窗口翻转效果

  • 效果

  •  摘要

     其实这就是很简单的一个项目,将窗口设置为透明然后使用一个可翻转的Flipable控件,然后将正反两面的内容填充一下。最后我在原有的基础上加了一个高度变化的动画,使原始的翻转看起来不那么的僵硬,另外,在win7的电脑上,翻转的过程中上下边缘有一定的失帧,但是win10的窗口上却没有出现。

  • 代码

import QtQuick 2.10
import QtQuick.Window 2.10

Window {
    id:rootWindow
    visible: true
    width: 640
    height: 480
    title: qsTr("闻天语~")
    flags:Qt.Window | Qt.FramelessWindowHint//窗口设置为无边框
    color: "transparent"//颜色为透明

    Flipable {
        id: flipable
        width: 240
        height: 240

        property bool flipped: false//翻转状态保存
        front:  Rectangle{//正面的内容
            id:front
            height: rootWindow.height
            width: rootWindow.width
            color: "gray"
            anchors.centerIn: parent
            Text {
                id: name
                text: "我是正面"
                color: "green"
                anchors.centerIn: parent
                font.pointSize: 14
                font.family: "微软雅黑"
            }
        }
        back: Rectangle{//背面的内容
            id:back
            height: rootWindow.height
            width: rootWindow.width
            color: "lightgray"
            anchors.centerIn: parent
            Text {
                id: name1
                text: "我是背面"
                color: "blue"
                anchors.centerIn: parent
                font.pointSize: 14
                font.family: "微软雅黑"
            }
        }

        transform: Rotation {
            id: rotation
            origin.x: flipable.width/2
            origin.y: flipable.height/2
            axis.x: 0; axis.y: 1; axis.z: 0
            angle: 0
        }
        SequentialAnimation {//接序动画(正面到背面的高度变化)
            id:toback
            NumberAnimation{ target: front; property: "height";from: rootWindow.height;to:rootWindow.height-200;duration:250}
            NumberAnimation{target: back;property: "height";from: rootWindow.height-200;to:rootWindow.height;duration: 250}
        }
        SequentialAnimation {//接序动画(背面到正面的高度变化)
            id:tofront
            NumberAnimation{ target: back; property: "height";from: rootWindow.height;to:rootWindow.height-200;duration:250}
            NumberAnimation{target: front;property: "height";from: rootWindow.height-200;to:rootWindow.height;duration: 250}
        }
        states: State {
            name: "back"
            PropertyChanges { target: rotation; angle:180 }//将rotation角度调整为180度
            when: flipable.flipped//当flipable.flipped为真的时候
        }

        transitions: Transition {//转动的动画
            NumberAnimation { target: rotation; property: "angle"; duration: 500 }
        }
    }
    MouseArea {//鼠标事件
        anchors.fill: parent
        onClicked: {
            flipable.flipped = !flipable.flipped//翻转状态切换
                            if(flipable.flipped){//根据翻转状态,调用不同的翻转高度变化动画
                                toback.start()
                                console.log("1")
                            }else{
                                tofront.start()
                                console.log("2")
                            }
        }
    }
}

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值