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. Adding Component dynamically to stacklayout at specific index
Forum Updated to NodeBB v4.3 + New Features

Adding Component dynamically to stacklayout at specific index

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 827 Views 1 Watching
  • 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.
  • J Offline
    J Offline
    James A
    wrote on last edited by
    #1

    I am able to dynamially add componets to stacklayout, but not able to insert at specific position. I am able insert tabbutton at position 1 for Tabbar , but not for StackLayout.

    I tried this function layout.children.push(object) but this did not help me.
    How to insert ChargerCalibration screen at position 1 in StackLayout

    Page {
        id:setuppage
    
        Component {
            id: tabButton
            TabButton {
                text: qsTr("screen 1")
            }
        }
    
        Component{
            id : calibraScreen
            ChargerCalibration{}
        }
    
        Component.onCompleted:  {
            var tab = tabButton.createObject(tabBar)
            tabBar.insertItem(1,tab)
    
            var object = calibraScreen.createObject(layout)
            layout.children.push(object)
    
        }
    
        TabBar {
            id: tabBar
            width: parent.width
            spacing: 2
    
            TabButton {
                text: qsTr("I/O Parameters")
            }
    
            TabButton {
                text: qsTr("Device Information")
            }
        }
    
        StackLayout {
            id: layout
            width: parent.width
            height: parent.height-tabBar.height
            currentIndex: tabBar.currentIndex
            anchors.top:tabBar.bottom
    
            IOInfo{}
    
            DeviceInfo{}
    
        }
    }
    
    
    1 Reply Last reply
    0
    • F Offline
      F Offline
      freedbrt
      wrote on last edited by freedbrt
      #2

      When you call this line:

      var object = calibraScreen.createObject(layout)
      

      You are already added new object as a parent of the StackLayout, and it's automatically add to the end of the children. You can modify the order only change of the parent. For example:

      StackOrder {
         id: stack
         Item { id: a }
         Item { id: b }
         Item { id: c }
      }
      
      Component.onCompleted: {
         a.parent = null // it can be null, or other visible/non visible temp element
         b.parent = null
         c.parent = null
         // and then add order what you want
         c.parent = stack // now it's first element
         a.parent = stack // now it's second element
         b.parent = stack // now it's third element
      }
      
      

      But it is a bay way, and you are doing something wrong.

      1 Reply Last reply
      0

      • Login

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