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. Pass thru properties?
Forum Updated to NodeBB v4.3 + New Features

Pass thru properties?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 4 Posters 684 Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      Is this what you want?
      https://stackoverflow.com/questions/26733011/how-to-declare-list-property-in-qml

      SPlattenS 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        Is this what you want?
        https://stackoverflow.com/questions/26733011/how-to-declare-list-property-in-qml

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        @JoeCFD , not sure, its a work in progress this is what I have so far, StaleDataModel.qml:

        import QtQuick 2.0
        
        Item {
            id: root
            property bool initialised : false
            property string text: "N/A"
            property string color: "#777777"
        
            Text {
                text: root.text
                color: root.color
                font.pointSize: parent.width < 150 ? 30 : 16
                horizontalAlignment: Text.AlignRight
                verticalAlignment: Text.AlignTop
            }
        }
        

        Ignore the properties that I've created already, what I want to do is allow any QML that includes an instance of StaleDataModel to be able to access any properties the Text control and any properties of any other object that I might include without having to expose every single property. I plan to add an Image to the file.

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          Is it possible to add an id to Text and then add functions in Item root to get any property of Text or Image?

          SPlattenS 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            Is it possible to add an id to Text and then add functions in Item root to get any property of Text or Image?

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by SPlatten
            #5

            @JoeCFD , Yes I can add an id to the Text, in fact I have already:

            import QtQuick 2.0
            
            Item {
                id: root
                property string color: "#777777"
                property string text: "N/A"
            
                Text {
                    id: rText
                    text: root.text
                    font.pointSize: parent.width < 150 ? 30 : 16
                    horizontalAlignment: Text.AlignRight
                    verticalAlignment: Text.AlignTop
                }
                property var anchors: rText.anchors
                property var color: tText.color
            }
            

            Still playing with it. So far no luck.

            Example of what I'd like to do:

                StaleDataModel {
                    id:hdgValue
                    rText.anchors.top: parent.top
                    rText.color: '#ff0000'
                    rText.width: 256
                }
            

            However this doesn't work.

            1 Reply Last reply
            0
            • JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

              use function
              function getTextColor() {
              return rText.color;
              }

              SPlattenS 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                use function
                function getTextColor() {
                return rText.color;
                }

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                @JoeCFD , I can achieve the same as that by defining a property for the text color, but thats not what I want. I would like to be able to access any text attribute / property without having to write a property or function for every single property / attribute.

                1 Reply Last reply
                0
                • JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by
                  #8

                  This may help a bit
                  https://stackoverflow.com/questions/29709427/call-function-or-property-in-another-qml-file-inside-a-tabview-in-qml

                  1 Reply Last reply
                  0
                  • fcarneyF Offline
                    fcarneyF Offline
                    fcarney
                    wrote on last edited by fcarney
                    #9

                    TheItem.qml

                    Item {
                      property alias rText: rtext
                      Text {
                        id: rtext
                      }
                    }
                    

                    Now you can access every property of rtext through the alias rText in the root Item.

                    Edit: Like this:

                    TheItem {
                      rText.text: "hello"
                    }
                    

                    C++ is a perfectly valid school of magic.

                    1 Reply Last reply
                    2
                    • L Offline
                      L Offline
                      lemons
                      wrote on last edited by lemons
                      #10

                      If you only want to extend the "Text" item, why don't you use it as root item in your qml file?
                      You don't have to wrap everything with an Item.

                      // StaleDataModel.qml
                      import QtQuick 2.0
                      
                      // use Text als root item, so all default properties of Text will be available automatically
                      Text {
                          // define it somehow generic, so you can reuse the item with different settings
                          property int fontSizeBreakPoint: 150
                          property int largeFontSize: 30
                          property int smallFontSize: 16
                          property color defaultColor: "#777777"
                      
                          color: defaultColor
                          font.pointSize: parent.width < fontSizeBreakPoint ? largeFontSize : smallFontSize
                          horizontalAlignment: Text.AlignRight
                          verticalAlignment: Text.AlignTop
                      }
                      
                      // SomeOther.qml
                      StaleDataModel{
                          anchors.top: parent.top
                          color: "#ff0000"
                          text: "someText"
                      }
                      
                      SPlattenS 1 Reply Last reply
                      0
                      • L lemons

                        If you only want to extend the "Text" item, why don't you use it as root item in your qml file?
                        You don't have to wrap everything with an Item.

                        // StaleDataModel.qml
                        import QtQuick 2.0
                        
                        // use Text als root item, so all default properties of Text will be available automatically
                        Text {
                            // define it somehow generic, so you can reuse the item with different settings
                            property int fontSizeBreakPoint: 150
                            property int largeFontSize: 30
                            property int smallFontSize: 16
                            property color defaultColor: "#777777"
                        
                            color: defaultColor
                            font.pointSize: parent.width < fontSizeBreakPoint ? largeFontSize : smallFontSize
                            horizontalAlignment: Text.AlignRight
                            verticalAlignment: Text.AlignTop
                        }
                        
                        // SomeOther.qml
                        StaleDataModel{
                            anchors.top: parent.top
                            color: "#ff0000"
                            text: "someText"
                        }
                        
                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by SPlatten
                        #11
                        This post is deleted!
                        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