Qt基于Qml图片翻转演示

这篇博客介绍了如何使用Qt Quick的Flipable组件实现在QML中图片的水平、垂直和三维翻转,并通过RadioButtons和Button实现控制。展示了旋转前后的图片切换和动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果: 

 qml源码

import QtQuick 2.12
import QtQuick.Controls 2.12

ApplicationWindow {
    id: root
    visible: true
    width: 800
    height: 640
    title: qsTr("Qt基于Qml图片翻转演示")

    //翻转组件
    Flipable{
        id: flip
        width: parent.width
        height: parent.height
        anchors.centerIn: parent

        property bool flipped: false

        //旋转前图片
        front:Image{
            anchors.fill: parent
            source: "qrc:/images/front.png"
        }
        //旋转后图片
        back:Image{
            anchors.fill: parent
            source: "qrc:/images/back.png"
        }

        //旋转
        transform: Rotation{
            id: rotation
            origin.x: flip.width / 2
            origin.y: flip.height / 2
            axis.x: idX.checked
            axis.y: idY.checked
            axis.z: idZ.checked
            angle: 0
        }

        states:State{
            PropertyChanges {
                target: rotation
                angle:180
            }
            when:flip.flipped
        }

        //翻转动画
        transitions: Transition{
            NumberAnimation{
                target:rotation //目标
                properties: "angle"
                duration:1000
            }
        }
    }

    //下面操作按钮
    Row{
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 6
        height: 30
        spacing: 10
        RadioButton{
            id: idX
            height: 24
            text: qsTr("X")
            checked: true
            background: Rectangle{
                color:"red"
                radius: 5
            }
        }

        RadioButton{
            id: idY
            height: 24
            text: qsTr("Y")
            background: Rectangle{
                color:"red"
                radius: 5
            }
        }

        RadioButton{
            id: idZ
            height: 24
            text: qsTr("Z")
            background: Rectangle{
                color:"red"
                radius: 5
            }
        }
        Button{
            height: 30
            width: 100
            text: qsTr("Flip")
            background: Rectangle{
                color:"red"
                radius: 5
            }
            onClicked: flip.flipped = !flip.flipped
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

自由软件开发者

有你的鼓励,我会更加努力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值