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. Get items after loading a qml file using the Loader QML
Forum Updated to NodeBB v4.3 + New Features

Get items after loading a qml file using the Loader QML

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.2k 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.
  • T Offline
    T Offline
    tarod.net
    wrote on last edited by
    #1

    What is the best way to get an item in a different QML file?

    I have something like that:

    @
    Button {
    text: qsTr("text")
    onClicked: {
    onClicked: circleLoader.source = "circle.qml";
    }
    }
    @

    And I am getting the attribute width in circle.qml - this file has many rectangles - using this line of code:

    @
    circleLoader.children[0].width
    @

    Does anyone know a better way of doing this?

    Thanks!

    "Individually, we are one drop. Together, we are an ocean."

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Try with circleLoader.item.width

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tarod.net
        wrote on last edited by
        #3

        Yes, that works, but I get the value for the first item in circle.qml.

        For example, if I have two items, how can I get the width for the second item?

        "Individually, we are one drop. Together, we are an ocean."

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

          You can access the children object of Item. That is the only way. Your posting already included this.

          You can try with only this as you have done it.

          @ console.log(pageL.item.children[0].width)
          console.log(pageL.item.children[1].width)
          @

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tarod.net
            wrote on last edited by
            #5

            [quote author="Dheerendra" date="1407907351"]You can access the children object of Item. That is the only way. Your posting already included this.

            You can try with only this as you have done it.

            @ console.log(pageL.item.children[0].width)
            console.log(pageL.item.children[1].width)
            @[/quote]

            OK, thank you very much.

            "Individually, we are one drop. Together, we are an ocean."

            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