Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
How to use a Flickable inside a Flipable: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
back: Flickable {<br /> anchors.fill: parent<br /> contentHeight: backText.height<br /> contentWidth: backText.width | back: Flickable {<br /> anchors.fill: parent<br /> contentHeight: backText.height<br /> contentWidth: backText.width | ||
Text {<br /> id: backText<br /> text: qsTr( | Text {<br /> id: backText<br /> text: qsTr("Hello Back of the World")<br /> } | ||
onFlickEnded: console.debug( | onFlickEnded: console.debug("back flick ended")<br /> onFlickStarted: console.debug("back flick started") | ||
MouseArea {<br /> anchors.fill: parent<br /> onPressAndHold: {<br /> console.debug( | MouseArea {<br /> anchors.fill: parent<br /> onPressAndHold: {<br /> console.debug("back enabling flipping")<br /> flipableMouseArea.toggleEnabled()<br /> }<br /> }<br /> } | ||
front: Flickable {<br /> anchors.fill: parent<br /> contentHeight: frontText.height<br /> contentWidth: frontText.width | front: Flickable {<br /> anchors.fill: parent<br /> contentHeight: frontText.height<br /> contentWidth: frontText.width | ||
Text {<br /> id: frontText<br /> text: qsTr( | Text {<br /> id: frontText<br /> text: qsTr("Hello Front of the World")<br /> } | ||
onFlickEnded: console.debug( | onFlickEnded: console.debug("front flick ended")<br /> onFlickStarted: console.debug("front flick started") | ||
MouseArea {<br /> anchors.fill: parent<br /> onPressAndHold: {<br /> console.debug( | MouseArea {<br /> anchors.fill: parent<br /> onPressAndHold: {<br /> console.debug("front enabling flipping")<br /> flipableMouseArea.toggleEnabled()<br /> }<br /> }<br /> } | ||
transform: Rotation {<br /> id: rotation<br /> origin.x: flipable1.width/2<br /> origin.y: flipable1.height/2<br /> axis.x: 0; axis.y: 1; axis.z: 0 // set axis.y to 1 to rotate around y-axis<br /> angle: 0 // the default angle<br /> } | transform: Rotation {<br /> id: rotation<br /> origin.x: flipable1.width/2<br /> origin.y: flipable1.height/2<br /> axis.x: 0; axis.y: 1; axis.z: 0 // set axis.y to 1 to rotate around y-axis<br /> angle: 0 // the default angle<br /> } | ||
states: State {<br /> name: | states: State {<br /> name: "back"<br /> PropertyChanges { target: rotation; angle: 180 }<br /> when: flipable1.flipped<br /> } | ||
transitions: Transition {<br /> NumberAnimation { target: rotation; property: | transitions: Transition {<br /> NumberAnimation { target: rotation; property: "angle"; duration: flipable1.transitionDuration }<br /> } | ||
MouseArea {<br /> id: flipableMouseArea<br /> anchors.fill: parent<br /> onPressAndHold: toggleEnabled()<br /> onClicked: flipable1.flipped = !flipable1.flipped | MouseArea {<br /> id: flipableMouseArea<br /> anchors.fill: parent<br /> onPressAndHold: toggleEnabled()<br /> onClicked: flipable1.flipped = !flipable1.flipped | ||
function toggleEnabled() {<br /> console.debug( | function toggleEnabled() {<br /> console.debug("flipping toggled by press and hold")<br /> enabled = ! enabled<br /> }<br /> }<br /> }<br />}<br /></code><br />[[Category:Developing_with_Qt::Qt Quick]] |
Revision as of 14:34, 24 February 2015
In a QtQuick application I'm writing I need a Flipable that has Flickable objects on its front and back. My solution is to use Press-and-Hold mouse events to toggle on and off the flipping feature of the Flipable. With flipping disabled, the Flickable objects can receive their flicking events. I use another Press-and-Hold mouse event on one of the Flickables to re-enable flipping.
<br />// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5<br />import QtQuick 1.1
Rectangle {<br /> width: 360<br /> height: 360
Flipable {<br /> id: flipable1<br /> property bool flipped: false
anchors.fill: parent
back: Flickable {<br /> anchors.fill: parent<br /> contentHeight: backText.height<br /> contentWidth: backText.width
Text {<br /> id: backText<br /> text: qsTr("Hello Back of the World")<br /> }
onFlickEnded: console.debug("back flick ended")<br /> onFlickStarted: console.debug("back flick started")
MouseArea {<br /> anchors.fill: parent<br /> onPressAndHold: {<br /> console.debug("back enabling flipping")<br /> flipableMouseArea.toggleEnabled()<br /> }<br /> }<br /> }
front: Flickable {<br /> anchors.fill: parent<br /> contentHeight: frontText.height<br /> contentWidth: frontText.width
Text {<br /> id: frontText<br /> text: qsTr("Hello Front of the World")<br /> }
onFlickEnded: console.debug("front flick ended")<br /> onFlickStarted: console.debug("front flick started")
MouseArea {<br /> anchors.fill: parent<br /> onPressAndHold: {<br /> console.debug("front enabling flipping")<br /> flipableMouseArea.toggleEnabled()<br /> }<br /> }<br /> }
transform: Rotation {<br /> id: rotation<br /> origin.x: flipable1.width/2<br /> origin.y: flipable1.height/2<br /> axis.x: 0; axis.y: 1; axis.z: 0 // set axis.y to 1 to rotate around y-axis<br /> angle: 0 // the default angle<br /> }
states: State {<br /> name: "back"<br /> PropertyChanges { target: rotation; angle: 180 }<br /> when: flipable1.flipped<br /> }
transitions: Transition {<br /> NumberAnimation { target: rotation; property: "angle"; duration: flipable1.transitionDuration }<br /> }
MouseArea {<br /> id: flipableMouseArea<br /> anchors.fill: parent<br /> onPressAndHold: toggleEnabled()<br /> onClicked: flipable1.flipped = !flipable1.flipped
function toggleEnabled() {<br /> console.debug("flipping toggled by press and hold")<br /> enabled = ! enabled<br /> }<br /> }<br /> }<br />}<br />