Flipable Element Reference

The Flipable item provides a surface that can be flipped.

[Inherits Item]

This element was introduced in Qt 4.7.

Detailed Description

The Flipable item provides a surface that can be flipped.

Flipable is an item that can be visibly "flipped" between its front and back sides, like a card. It is used together with Rotation, State and Transition elements to produce a flipping effect.

The front and back properties are used to hold the items that are shown respectively on the front and back sides of the flipable item.

Example Usage

The following example shows a Flipable item that flips whenever it is clicked, rotating about the y-axis.

This flipable item has a flipped boolean property that is toggled whenever the MouseArea within the flipable is clicked. When flipped is true, the item changes to the "back" state; in this state, the angle of the Rotation item is changed to 180 degrees to produce the flipping effect. When flipped is false, the item reverts to the default state, in which the angle value is 0.

  1. import QtQuick 1.0
  3. Flipable  {
  4.     id: flipable
  5.     width: 240
  6.     height: 240
  8.     property bool flipped: false
  10.     front: Image  { source: "front.png"; anchors.centerIn: parent }
  11.     back: Image  { source: "back.png"; anchors.centerIn: parent }
  13.     transform: Rotation  {
  14.         id: rotation
  15.         origin.x: flipable.width/2
  16.         origin.y: flipable.height/2
  17.         axis.x: 0; axis.y: 1; axis.z: 0     // set axis.y to 1 to rotate around y-axis
  18.         angle: 0    // the default angle
  19.     }
  21.     states: State  {
  22.         name: "back"
  23.         PropertyChanges  { target: rotation; angle: 180 }
  24.         when: flipable.flipped
  25.     }
  27.     transitions: Transition  {
  28.         NumberAnimation  { target: rotation; property: "angle"; duration: 4000 }
  29.     }
  31.     MouseArea  {
  32.         anchors.fill: parent
  33.         onClicked: flipable.flipped = !flipable.flipped
  34.     }
  35. }

The Transition creates the animation that changes the angle over four seconds. When the item changes between its "back" and default states, the NumberAnimation animates the angle between its old and new values.

See QML States for details on state changes and the default state, and QML Animation and Transitions for more information on how animations work within transitions.


Property Documentation

The front and back sides of the flipable.

The side of the Flipable currently visible. Possible values are Flipable.Front and Flipable.Back.

Notes provided by the Qt Community

No notes