在之前的很多练习及教程中,我们展示了如何在QML语言设计中使用ListView及GridView来展示我们所需要的效果.在今天的教程中,我们来深刻体会一下如何使用QML语言中的PathView来展示我们的效果.在PathView中,我们可以用它来显示旋转木马的效果.如果大家有使用我们的Ubuntu Scope的话,可能大家已经曾经使用carousel显示模板.在很多的场合中可以实现很炫的显示效果.
import QtQuick 2.0 import Ubuntu.Components 1.1 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "carousel0.liu-xiao-guo" property int pathMargin: units.gu(10) width: units.gu(60) height: units.gu(85) Page { title: i18n.tr("carousel0") PathView { id: view anchors.fill: parent model: 32 delegate: Text { text: index } path: Path { startX: 0 startY: pathMargin PathLine { x: view.width; y: pathMargin } } } } }
PathLine { x: view.width; y: pathMargin }
import QtQuick 2.0 ListModel { ListElement { title: "Calendar"; iconSource: "icons/calendar.png" } ListElement { title: "Setup"; iconSource: "icons/develop.png" } ListElement { title: "Internet"; iconSource: "icons/globe.png" } ListElement { title: "Messages"; iconSource: "icons/mail.png" } ListElement { title: "Music"; iconSource: "icons/music.png" } ListElement { title: "Call"; iconSource: "icons/phone.png" } ListElement { title: "PodCast"; iconSource: "icons/podcast.png" } ListElement { title: "Recycle"; iconSource: "icons/recycle.png" } }
import QtQuick 2.0 import Ubuntu.Components 1.1 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "carousel0.liu-xiao-guo" property int pathMargin: units.gu(10) width: units.gu(60) height: units.gu(85) Page { title: i18n.tr("carousel0") PathView { id: view width: parent.width height: parent.height*.2 model: Model0 {} delegate: Item { id: wrapper width: parent.width/4 height: width Image { width: parent.width*.5 height: width source: iconSource } } path: Path { startX: 0 startY: pathMargin PathLine { x: view.width; y: pathMargin } } } } }
import QtQuick 2.0 import Ubuntu.Components 1.1 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "carousel.liu-xiao-guo" property int pathMargin: units.gu(10) width: units.gu(60) height: units.gu(85) Page { title: i18n.tr("carousel") PathView { id: view width: parent.width height: parent.height*.2 model: Model0 {} delegate: Item { id: wrapper width: parent.width/4 height: width scale: PathView.scale Image { width: parent.width*.5 height: width source: iconSource } } path: Path { startX: 0 startY: pathMargin PathAttribute { name: "scale"; value: 0.3 } PathLine { x: view.width/4; y: pathMargin } PathAttribute { name: "scale"; value: 0.6 } PathLine { x: view.width*2/4; y: pathMargin } PathAttribute { name: "scale"; value: 1.0 } PathLine { x: view.width*3/4; y: pathMargin } PathAttribute { name: "scale"; value: 0.6 } PathLine { x: view.width*4/4; y: pathMargin } PathAttribute { name: "scale"; value: 0.3 } } } } }
PathAttribute { name: "scale"; value: 0.3 }
delegate: Item { id: wrapper width: parent.width/4 height: width scale: PathView.scale Image { width: parent.width*.5 height: width source: iconSource } }
PathView { id: view1 // anchors.fill: parent width: parent.width height: parent.height*0.8 anchors.top: view.bottom model: Model1 {} delegate: mydelegate path: Path { startX: view1.width/2; startY: 2* view1.height / 3; PathAttribute { name: "opacity"; value: 1 } PathAttribute { name: "scale"; value: 1 } PathAttribute { name: "z"; value: 100 } PathQuad { x: view1.width/2; y: view1.height / 3; controlX: view1.width+200; controlY: view1.height/2} PathAttribute { name: "opacity"; value: 0.3 } PathAttribute { name: "scale"; value: 0.5 } PathAttribute { name: "z"; value: 0 } PathQuad { x: view1.width/2; y: 2*view1.height / 3; controlX: -200; controlY: view1.height/2} } }