标签:
我们知道ListView在QML应用中扮演非常重要的角色。看看我们的很多的应用都是在使用ListView。那么当我们点击ListView中的item并导航到另外一个页面呢?其实这样的方法有很多。在这篇文章中,我们来介绍其中的几种。开发者可以参照其中的设计,或自己想出更好的设计。
ListView { id: listview clip: true anchors.fill: parent model:mymodel header: Text { text: "This is the header" font.pixelSize: 30 Rectangle { anchors.top: parent.bottom width: listview.width height: units.gu(0.4) color: "blue" } } delegate: MyDelegate {} footer: Text { text: "This is the footer" font.pixelSize: 30 } } Item { id: popup visible: false clip: true property url loadUrl onLoadUrlChanged: { opacity = 0; visible = (loadUrl == '' ? false : true); console.log("opacity: " + opacity ); console.log("visible: " + visible ); } anchors.fill: parent Rectangle { id: bg anchors.fill: parent color: "white" } MouseArea{ anchors.fill: parent enabled: popup.visible //Eats mouse events } Loader{ focus: true source: popup.loadUrl width: parent.width height: parent.height -toolbar.height } Rectangle { id: toolbar width: parent.width height: units.gu(4) anchors.bottom: parent.bottom color: "blue" Icon { name: "previous" width: units.gu(3.5) height: units.gu(3.5) MouseArea { anchors.fill: parent onClicked: { popup.loadUrl = ""; ani.running = true; } } } } NumberAnimation on opacity { id: ani from: 0 to: 1 duration: 3000 } } }
import QtQuick 2.0 Item { property Item item width: listview.width height: units.gu(8) Text { id: text text: title anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: units.gu(10) font.pixelSize: 30 } Rectangle { anchors.top: text.bottom width: parent.width height: units.gu(0.2) color: "gray" } Image { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter source: "images/arrow.png" rotation: -90 } MouseArea { anchors.fill: parent onClicked: { console.log("it is clicked"); popup.loadUrl = "ExampleQml.qml" } } }
Row { id: view ListView { id: listview clip: true width: root.width height: root.height model:mymodel header: Text { text: "This is the header" font.pixelSize: 30 Rectangle { anchors.top: parent.bottom width: listview.width height: units.gu(0.4) color: "blue" } } delegate: MyDelegate {} footer: Text { text: "This is the footer" font.pixelSize: 30 } } // This is the second page DetailedPage { id: detailPage width: root.width height: root.height } Behavior on x { NumberAnimation { duration: 500 } } }
import QtQuick 2.0 Item { property Item item width: listview.width height: units.gu(8) Text { id: text text: title anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: units.gu(10) font.pixelSize: 30 } Rectangle { anchors.top: text.bottom width: parent.width height: units.gu(0.2) color: "gray" } Image { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter source: "images/arrow.png" rotation: -90 } MouseArea { anchors.fill: parent onClicked: { // popup.loadUrl = "ExampleQml.qml" view.x = -root.width; } } }
标签:
原文地址:http://blog.csdn.net/ubuntutouch/article/details/45481835