Home > Mobile >  how to add qml file in swipeview
how to add qml file in swipeview

Time:12-14

I was trying to use swipe view In swipe view i need to add qml file into it so every swipe i need to get one qml file to show i need to get 7 qml file in 7 swipe and i need add global property in every swipe view

I try to loader to get qml file but i am not able to add global property Because the qml file are already used in another swipe view i need to use global property and change the value

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

Page
{

    id:mfcscreens

    Rectangle{
        height:wavescreen.height
        width: wavescreen.width

        SwipeView{
            id:swipeview
            anchors.fill:parent
            currentIndex: 0
            spacing: 4


            Item {
                id:page1
                Loader{
                    id:mainwavescreen
                    source: "MfcWavefoam.qml"
                }
            }
            Item {
                id:page2

                Loader{
                    id:leads12
                    source: "Leads12.qml"
                    Item{
                        property int speed: 5;
                        property int gain: 10;
                        property int xValue: 976
                        property int degreeValue: 143

                    }

                }

           }
            Item {
                id:page3
                Loader{
                    id:leads3of1
                    source: "Leads3of1.qml"
                }
            }
            Item {
                id:page4
                Loader{
                    id:leads3of2
                    source: "Leads3of2.qml"
                }
            }
            Item {
                id:page5
                Loader{
                    id:leads3of3
                    source: "Leads3of3.qml"
                }
            }
            Item {
                id:page6
                Loader{
                    id:leads3of4
                    source: "Leads3of4.qml"
                }
            }
            Item {
                id:page7
                Loader{
                    id:leads6of1
                    source: "Leads6of1.qml"
                }

            }
            Item {
                id:page8
                Loader{
                    id:leads6of2
                    source: "Leads6of2.qml"
                }

            }


        }
    }

}

CodePudding user response:

I think, you have several problems. So start with the first one. For your SwipeView to work you should provide a PageIndicator. So add something like that below our view:

PageIndicator {
    id: indicator

    count: swipeView.count
    currentIndex: swipeView.currentIndex

    anchors.bottom: swipeView.bottom
    anchors.horizontalCenter: parent.horizontalCenter
}

You don't need to use loaders for your pages. You could just add the components directly to your items:

Item {
    id:page8
    // if your file name is called Leads6of2.qml and is part of your project
    Leads6of2 {}
}

The part with the global property is unclear to me. Please rephrase this problem!

  • Related