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. How To Accessing Data Between QML Objects?
Forum Update on Monday, May 27th 2025

How To Accessing Data Between QML Objects?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 930 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.
  • N Offline
    N Offline
    Nima Ghorab
    wrote on 31 Aug 2018, 23:07 last edited by Nima Ghorab
    #1

    Hello guys.
    I have a question about accessing possibilities between QML objects.

    page{
    ....
        ListView{
            id: listview
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            width: parent.width / 2
            height: parent.height / 2
            clip: true
            property Item header_component
            header: Rectangle{
                id: header_rectangle
                z: 2
                width: parent.width
                height: textID.implicitHeight
                color: "Orange"
                //Component.onCompleted: console.log(parent.width)
                Text{id:textID ;text: language_selector_alias.currentIndex === 0 ? qsTr("NACA " + chart.naca_model_on_chart_header + " Point Coordinates") : qsTr(" مختصات نقاط ناکا" + chart.naca_model_on_chart_header); font.family: font_of_options; font.pixelSize: 30; color: "White"; anchors.horizontalCenter: parent.horizontalCenter}
            }
            ScrollBar.vertical: ScrollBar {
                id: control
                //y: header_component.height
                height: 2
                size: 0.3
                position: 0.2
                active: true
                orientation: Qt.Vertical
                contentItem: Rectangle {
                    implicitWidth: 6
                    implicitHeight: 100
                    radius: width / 2
                    color: control.pressed ? "White" : "Green"
                }
            }
    .....
    }
    

    I want to access to header_rectangle properties in control (scrollBar) object but QML does not allow me to do that!
    I even try to put header_rectangle in Component but the problem still persist!
    Also I try global variables (manipulate them in component.onCompleted signal) with no luck!
    Can anyone point me to right direction?
    Thanks in advance.

    O 1 Reply Last reply 1 Sept 2018, 01:00
    0
    • N Nima Ghorab
      31 Aug 2018, 23:07

      Hello guys.
      I have a question about accessing possibilities between QML objects.

      page{
      ....
          ListView{
              id: listview
              anchors.bottom: parent.bottom
              anchors.right: parent.right
              width: parent.width / 2
              height: parent.height / 2
              clip: true
              property Item header_component
              header: Rectangle{
                  id: header_rectangle
                  z: 2
                  width: parent.width
                  height: textID.implicitHeight
                  color: "Orange"
                  //Component.onCompleted: console.log(parent.width)
                  Text{id:textID ;text: language_selector_alias.currentIndex === 0 ? qsTr("NACA " + chart.naca_model_on_chart_header + " Point Coordinates") : qsTr(" مختصات نقاط ناکا" + chart.naca_model_on_chart_header); font.family: font_of_options; font.pixelSize: 30; color: "White"; anchors.horizontalCenter: parent.horizontalCenter}
              }
              ScrollBar.vertical: ScrollBar {
                  id: control
                  //y: header_component.height
                  height: 2
                  size: 0.3
                  position: 0.2
                  active: true
                  orientation: Qt.Vertical
                  contentItem: Rectangle {
                      implicitWidth: 6
                      implicitHeight: 100
                      radius: width / 2
                      color: control.pressed ? "White" : "Green"
                  }
              }
      .....
      }
      

      I want to access to header_rectangle properties in control (scrollBar) object but QML does not allow me to do that!
      I even try to put header_rectangle in Component but the problem still persist!
      Also I try global variables (manipulate them in component.onCompleted signal) with no luck!
      Can anyone point me to right direction?
      Thanks in advance.

      O Offline
      O Offline
      ODБOï
      wrote on 1 Sept 2018, 01:00 last edited by
      #2

      hi @Nima-Ghorab
      listview.headerItem.height

      N 1 Reply Last reply 1 Sept 2018, 12:31
      2
      • O ODБOï
        1 Sept 2018, 01:00

        hi @Nima-Ghorab
        listview.headerItem.height

        N Offline
        N Offline
        Nima Ghorab
        wrote on 1 Sept 2018, 12:31 last edited by Nima Ghorab 9 Jan 2018, 13:16
        #3

        @LeLev thank you so much it works like a charm.
        I have just one more question.
        How can I access to properties of a Component object outside of itself in following code:

            Component{
                id: comp
                Rectangle{
                    id: rect_ID
                    z: 2
                    width: parent.width
                    height: textID.implicitHeight
                    color: "Orange"
                    Component.onCompleted: console.log(page.width)
                    Text{id:textID ;text: language_selector_alias.currentIndex === 0 ? qsTr("NACA " + chart.naca_model_on_chart_header + " Point Coordinates") : qsTr(" مختصات نقاط ناکا" + chart.naca_model_on_chart_header); font.family: font_of_options; font.pixelSize: 30; color: "White"; anchors.horizontalCenter: parent.horizontalCenter}
                }
            }
            Rectangle{
                id:???
                color: "Orange"
                //width: i
                Component.onCompleted: console.log(comp.width)
            }
        

        As far as I know, component just a inline encapsulation and we need to instantiate it in order to use its properties.
        Correct me if I'm wrong.
        Thank you so much.

        O 1 Reply Last reply 1 Sept 2018, 14:47
        0
        • N Nima Ghorab
          1 Sept 2018, 12:31

          @LeLev thank you so much it works like a charm.
          I have just one more question.
          How can I access to properties of a Component object outside of itself in following code:

              Component{
                  id: comp
                  Rectangle{
                      id: rect_ID
                      z: 2
                      width: parent.width
                      height: textID.implicitHeight
                      color: "Orange"
                      Component.onCompleted: console.log(page.width)
                      Text{id:textID ;text: language_selector_alias.currentIndex === 0 ? qsTr("NACA " + chart.naca_model_on_chart_header + " Point Coordinates") : qsTr(" مختصات نقاط ناکا" + chart.naca_model_on_chart_header); font.family: font_of_options; font.pixelSize: 30; color: "White"; anchors.horizontalCenter: parent.horizontalCenter}
                  }
              }
              Rectangle{
                  id:???
                  color: "Orange"
                  //width: i
                  Component.onCompleted: console.log(comp.width)
              }
          

          As far as I know, component just a inline encapsulation and we need to instantiate it in order to use its properties.
          Correct me if I'm wrong.
          Thank you so much.

          O Offline
          O Offline
          ODБOï
          wrote on 1 Sept 2018, 14:47 last edited by ODБOï 9 Jan 2018, 14:47
          #4

          hi
          @Nima-Ghorab said in How To Accessing Data Between QML Objects?:

          As far as I know, component just a inline encapsulation and we need to instantiate it in order to use its properties.

          not exactly see http://doc.qt.io/qt-5/qml-qtqml-component.html

          1 Reply Last reply
          1
          • O Offline
            O Offline
            ODБOï
            wrote on 1 Sept 2018, 14:49 last edited by
            #5

            create an instance of your component with a Loader

            N 1 Reply Last reply 1 Sept 2018, 14:51
            1
            • O ODБOï
              1 Sept 2018, 14:49

              create an instance of your component with a Loader

              N Offline
              N Offline
              Nima Ghorab
              wrote on 1 Sept 2018, 14:51 last edited by
              #6

              @LeLev thank you so much.

              1 Reply Last reply
              0

              6/6

              1 Sept 2018, 14:51

              • Login

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