如何在Qt 5.2 QML应用程序中实现分页 [英] How to implement pagination in a Qt 5.2 QML app

查看:130
本文介绍了如何在Qt 5.2 QML应用程序中实现分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个可一次显示3页的应用程序.中心页面显示3个显示sql查询结果1-3的矩形,左侧页面是来自查询结果4的图像的链接,右侧页面也是根据相同的查询构建的,并且布局不同.现在,我无法将这3个页面放到listmodel中,并且无法使用pathview使它看起来像一个分页器,因为所有3个页面都是不一致的,并且不是真正的模型,因此出现错误ListElement:不能包含嵌套元素.我正在粘贴下面的代码.我想要的是使用户能够在页面之间滑动,无论是涉及路径视图还是状态转换以及向mimick翻转页面的适当过渡:

I am trying to make an app which shows 3 pages at a time. The central page shows 3 rectangles displying sql query results 1-3 , the left page is a link to an image from query result 4, and the right page is also built from the same query and has a different layout. Now I am unable to fit these 3 pages into a listmodel and use pathview to make it look like a paginator, because all 3 pages are incongruent and not really a model, hence giving me error ListElement: cannot contain nested elements. I am pasting the code below. All i want is for the user to be able to flick between the pages, whether that involves a pathview or statechange with a decent transition to mimick flipping pages :

import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import "content"


Rectangle{
    property ListModel mainModel
    id: tripleView
    visible: true
    width: 800
    height: 1400

    PathView {
        model: mainModel
        delegate: mainDelegate
        id: paginator
        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5

        anchors.fill: parent
        path: Path {

            startX: -tripleView.width * mainModel.count / 2 + tripleView.width / 2;
            startY: tripleView.height / 2
            PathLine {
                x: tripleView.width * mainModel.count /2 + tripleView.width / 2
                y: tripleView.height * .5 }
        }
    }

    Component {
        id: mainDelegate

        Rectangle {
        width: tripleView.width
        height: tripleView.height
        }
    }

    ListModel {
        id: regionsModel
        ListElement {

            name: "Stomach"
        }
        ListElement {
            name: "Lung"
        }
        ListElement {
            name: "Colorectal"
        }
        ListElement {
            name: "Pancreas"
        }
        ListElement {
            name: "Urinary Bladder"
        }

    }

    ListModel {
        id: mainModel
        ListElement{
            Rectangle{
                id: tnmPage
                width: parent.width
                height: container.height


                Rectangle {
                    id: menu
                    z: 2
                    width: parent.width  ;
                    height: 75



                    Component {

                        id: appDelegate
                        Rectangle {
                            width: genericText.width + 10; height: parent.height
                            id: wrapper
                            color: PathView.isCurrentItem ? "yellow" : "white"
                            Text {
                                id: genericText
                                height: parent.height
                                font.pointSize: 12
                                verticalAlignment: Text.AlignVCenter
                                //                anchors.topMargin: wrapper.top
                                color: wrapper.PathView.isCurrentItem ? "red" : "black"
                                text: name
                            }

                            MouseArea {
                                //  width:parent.width; height: parent.height
                                anchors.fill: parent
                                hoverEnabled: true
                                onClicked: {
                                    var List = mWindow.printi(name)
                                    t.content = List[1]
                                    node.content = List[2]
                                    mets.content = List[3]
                                    view.currentIndex = index


                                }

                            }
                        }
                    }



                    PathView {
                        id: view
                        width: 2500
                        height: parent.height
                        anchors.rightMargin: 18
                        anchors.bottomMargin: 0
                        anchors.leftMargin: -18
                        anchors.topMargin: 0
                        anchors.fill: parent
                        //        anchors.bottom: parent.bottom
                        //        anchors.top: parent.top
                        //        preferredHighlightBegin: .1
                        //        preferredHighlightEnd: .6

                        highlightRangeMode: PathView.StrictlyEnforceRange
                        //        anchors.rightMargin: 0
                        //        anchors.bottomMargin: 0
                        //        anchors.leftMargin: 2
                        //        anchors.topMargin: -71

                        z: 1
                        highlight: Component {
                            Rectangle {
                                color: "yellow"
                                visible: PathView.onPath

                            }
                        }

                        focus: true
                        model: regionsModel
                        delegate: appDelegate

                        path: Path {

                            startX: 0; startY: view.height *.5
                            PathLine { x: menu.width; y: view.height * .5 }
                        }


                    }
                }



                Flickable {
                    id: flick

                    anchors.topMargin: menu.bottom
                    width: parent. width
                    height: parent. height - menu.height
                    contentWidth: parent.width+200
                    contentHeight: container.height // this is calculated on amount of text
                    PinchArea {
                        width: Math.max(flick.contentWidth, flick.width)
                        height: Math.max(flick.height, flick.height)
                        pinch.minimumScale: 0.5
                        pinch.maximumScale: 3

                        property real initialWidth
                        property real initialHeight
                        x: 0
                        y: 0
                        //![0]
                        onPinchStarted: {
                            initialWidth = flick.contentWidth
                            initialHeight = flick.contentHeight
                            flick.interactive = false
                        }
                        onPinchUpdated: {
                            t.fontSize = t.size*pinch.scale
                            node.fontSize = node.size * pinch.scale
                            mets.fontSize = mets.size * pinch.scale

                        }

                        onPinchFinished: {
                            flick.returnToBounds()
                            flick.interactive = true
                        }



                        Rectangle {
                            id: container

                            MouseArea {
                                anchors.fill: parent
                                onDoubleClicked: {

                                    t.fontSize = 12
                                    node.fontSize = t.size
                                    mets.fontSize = t.size
                                }


                            }


                            anchors.top: flick.top
                            width: parent.width
                            height: t.height + node.height + mets.height

                            StageBox {
                                id: t
                                anchors.top: container.top
                                color: "#6acbd3"
                            }

                            StageBox {
                                id: node
                                anchors.top: t.bottom
                                color: "#1fd77b"
                            }
                            StageBox {
                                id: mets
                                anchors.top: node.bottom
                                color: "blue"
                            }
                        }
                    }


                }
            }

}

我意识到上面的代码很长,但是我认为它可以使我对要实现的目标有所了解.到目前为止,我发现的示例具有显示图像且没有嵌套的简单页面.谢谢您的帮助.

I realise the code above is lengthy, but i think it will give some idea about what i am trying to achieve. The examples i have found so far have simple pages displaying images and no nesting. Thank you for your help.

推荐答案

尝试QML类型 VisualItemModel

Try QML type VisualItemModel http://qt-project.org/doc/qt-4.8/qml-visualitemmodel.html#details .good luck

这篇关于如何在Qt 5.2 QML应用程序中实现分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆