本页内容

Flipable QML Type

提供一个可翻转的表面。更多...

Import Statement: import QtQuick
Inherits:

Item

属性

详细说明

Flipable 是一种可以像卡片一样在正反两面之间进行可视“翻转”的组件。它可以与Rotation 、State 和Transition 类型配合使用,以产生翻转效果。

front 和back 属性分别用于存放可翻转项正面和背面的内容。

使用示例

以下示例展示了一个 Flipable 控件,每次点击时它都会围绕 y 轴旋转翻转。

该可翻转项具有一个名为flipped 的布尔属性,每当点击该可翻转项内的MouseArea 时,该属性就会切换。 当flipped 为true时,该项将切换到“背面”状态;在此状态下,Rotation 项的angle 值将更改为180度,以产生翻转效果。当flipped 为false时,该项将恢复到默认状态,此时angle 值为0。

import QtQuick

Flipable {
    id: flipable
    width: 240
    height: 240

    property bool flipped: false

    front: Image { source: "front.png"; anchors.centerIn: parent }
    back: Image { source: "back.png"; anchors.centerIn: parent }

    transform: Rotation {
        id: rotation
        origin.x: flipable.width/2
        origin.y: flipable.height/2
        axis.x: 0; axis.y: 1; axis.z: 0     // set axis.y to 1 to rotate around y-axis
        angle: 0    // the default angle
    }

    states: State {
        name: "back"
        PropertyChanges { target: rotation; angle: 180 }
        when: flipable.flipped
    }

    transitions: Transition {
        NumberAnimation { target: rotation; property: "angle"; duration: 4000 }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: flipable.flipped = !flipable.flipped
    }
}

Transition 创建了在四秒内改变角度的动画。当项目在“back”状态和默认状态之间切换时,NumberAnimation 会将角度从旧值动画过渡到新值。

有关状态变化和默认状态的详细信息,请参阅《Qt Quick 状态》;有关动画在过渡中的工作原理,请参阅《 Qt Quick 中的动画与过渡》。

另请参阅 《UI 组件:Flipable 示例》。

属性文档

back : Item

front : Item

可翻转物品的正面和背面。

side : enumeration [read-only]

当前可见的Flipable的一面。可能的取值为Flipable.Front 和Flipable.Back 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.