Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Resize and Item cretaed dynamically

Resize and Item cretaed dynamically

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 613 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.
  • carles.sole.grauC Offline
    carles.sole.grauC Offline
    carles.sole.grau
    wrote on last edited by carles.sole.grau
    #1

    Hi everyone,
    when I create and object dynamically:

    var widgetTemp = Qt.createComponent("./RemoteWidgets/RoundButtonWidget.qml");
    if (widgetTemp.status === Component.Ready)
       widgetsHolder.children.push( widgetTemp.createObject(container, {   width: widgetsHolder.cellWidth, height: widgetsHolder.cellHeight}));                                                                       
    

    As you can see I set the width and the height in relation to another property.

    My problem is that when this property changes (in this case widgetsHolder.cellWidth and widgetsHolder.cellHeight), my object not change its size.

    I found some info in this link: http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html
    When managing dynamically created objects, you must ensure the creation context outlives the created object. Otherwise, if the creation context is destroyed first, the bindings in the dynamic object will no longer work.
    But I don't know how to do it.
    So, how it can be done?
    Thank you

    1 Reply Last reply
    0
    • carles.sole.grauC Offline
      carles.sole.grauC Offline
      carles.sole.grau
      wrote on last edited by
      #2

      I've just got the solution, Qt.binding (http://doc.qt.io/qt-5/qml-qtqml-qt.html#binding-method) has to be used:

      var widgetTemp = Qt.createComponent("./RemoteWidgets/RoundButtonWidget.qml");
      if (widgetTemp.status === Component.Ready)
         widgetsHolder.children.push( widgetTemp.createObject(container, {   width:  Qt.binding(function() { return widgetsHolder.cellWidth }), height:  Qt.binding(function() { return widgetsHolder.cellHeight })}));     }),
      
      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