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?
QtWS25 Last Chance

How To Accessing Data Between QML Objects?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 921 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 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.

    ODБOïO 1 Reply Last reply
    0
    • N Nima Ghorab

      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.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi @Nima-Ghorab
      listview.headerItem.height

      N 1 Reply Last reply
      2
      • ODБOïO ODБOï

        hi @Nima-Ghorab
        listview.headerItem.height

        N Offline
        N Offline
        Nima Ghorab
        wrote on last edited by Nima Ghorab
        #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.

        ODБOïO 1 Reply Last reply
        0
        • N Nima Ghorab

          @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.

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #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
          • ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #5

            create an instance of your component with a Loader

            N 1 Reply Last reply
            1
            • ODБOïO ODБOï

              create an instance of your component with a Loader

              N Offline
              N Offline
              Nima Ghorab
              wrote on last edited by
              #6

              @LeLev thank you so much.

              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