Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to position dynamic created qml obj?

    QML and Qt Quick
    4
    5
    807
    Loading More Posts
    • 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.
    • M
      Mr Pang last edited by

      I have such code

      var compoment = Qt.createComponent("qrc:/ui/About.qml");
      var obj = compoment.createObject(window,{"width": list.width, "height": list.height});
      
                              
      

      How to set anchors value for obj? Such anchors.fill: parent

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Mr Pang last edited by

        @Mr-Pang
        simply set it on obj? :)

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User last edited by A Former User

          Hi! Either like this:

          var obj = compoment.createObject(window, {color: "pink", "anchors.centerIn":window.contentItem})
          

          Or like that:

          var obj = compoment.createObject(window, {color: "pink"})
          obj.anchors.centerIn = window.contentItem
          
          M 1 Reply Last reply Reply Quote 1
          • M
            Mr Pang @Guest last edited by

            @Wieland
            Oh,Thanks.
            But,why this not work:
            var obj = compoment.createObject(window, {color: "pink", "anchors.centerIn":parent})

            p3c0 1 Reply Last reply Reply Quote 0
            • p3c0
              p3c0 Moderators @Mr Pang last edited by p3c0

              @Mr-Pang said in How to position dynamic created qml obj?:

              @Wieland
              Oh,Thanks.
              But,why this not work:
              var obj = compoment.createObject(window, {color: "pink", "anchors.centerIn":parent})

              That too will work provided the parent is valid and found in that context or you can directly pass an id of the item which it should be centered on instead of parent.

              157

              1 Reply Last reply Reply Quote 1
              • First post
                Last post