Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. access to swipeview children from outside of it

access to swipeview children from outside of it

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlswipeviewrectangle
2 Posts 2 Posters 660 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MABahar
    wrote on last edited by MABahar
    #1

    Hi, I want to have a rectangle located on a swipeview and it should load different qml pages when swipeview index changes. please have look at following code:

    Item {
        SwipeView
        {
            id: swipView
            currentIndex: 0
            anchors.fill: parent
            Repeater
            {
                model: 3
                Page
                {
                    id: delegate
                    Button {
                        text: "<"
                        width: 18
                        height: 40
                        enabled: index > 0
                        onClicked:
                        {
                            delegate.SwipeView.view.decrementCurrentIndex()                        
                        }
                        anchors.left: parent.left
                        anchors.verticalCenter: parent.verticalCenter
                    }
    
                    Button {
                        text: ">"
                        width: 18
                        height: 40
                        enabled: index < delegate.SwipeView.view.count - 1
                        onClicked:
                        {
                            delegate.SwipeView.view.incrementCurrentIndex()                        
                        }
                        anchors.right: parent.right
                        anchors.verticalCenter: parent.verticalCenter
                    }
                    Rectangle
                    {
                        id: pgRect
                        state: "blue"
                        anchors
                        {
                            left: parent.left
                            top: parent.top
                            leftMargin: 18
                            topMargin: 18
                            rightMargin: 18
                            bottomMargin: 18
                            fill: parent
                        }
                        Loader
                        {
                            id: loader
                            anchors.fill: parent
                        }
                        Connections
                        {
                            target: loader.source != "" ? loader.item : null
                        }
                        states: [
                            State {
                                name: "page1"
                                PropertyChanges {
                                    target: loader
                                    source: "PageI.qml"
                                }
                            },
                            State {
                                name: "page2"
                                PropertyChanges {
                                    target: loader
                                    source: "PageII.qml"
                                }
                            },
    						State {
                                name: "page3"
                                PropertyChanges {
                                    target: loader
                                    source: "PageIII.qml"
                                }
                            }
                        ]
    
                    }
                }
            }
    		onCurrentIndexChanged: 
            {      
            
                if(swipView.currentIndex === 0)
                {
                    // change pgRect.state
                }
            
            }
        }
    }
    
    

    i want to have access to rectangle properties and change its state (changing the qml page loaded on rectangle) in onCurrentIndexChanged signal.
    but it says: pgRect is not defined.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by dheerendra
      #2

      Modify the Repeater as

      Repeater{
          id : rep1
          Page {
            property alias myrect : pgrect
      

      Access each element inside the repeater using rep1.itemAt(index).

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved