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 position dynamic created qml obj?
QtWS25 Last Chance

How to position dynamic created qml obj?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 1.1k 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.
  • M Offline
    M Offline
    Mr Pang
    wrote on last edited by
    #1

    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-worxR 1 Reply Last reply
    0
    • M Mr Pang

      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-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #3

        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
        1
        • ? 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 Offline
          M Offline
          Mr Pang
          wrote on last edited by
          #4

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

          p3c0P 1 Reply Last reply
          0
          • M Mr Pang

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

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by p3c0
            #5

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

            • Login

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