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 initiate a binding property updating by change another property from javascript?

How to initiate a binding property updating by change another property from javascript?

Scheduled Pinned Locked Moved QML and Qt Quick
qmlpropertyjavascript
3 Posts 3 Posters 1.2k 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.
  • D Offline
    D Offline
    DenisFromNN
    wrote on 20 Aug 2015, 19:05 last edited by DenisFromNN
    #1

    Hello

    I have some QML sample which sets a source of image and automatically changes its width and I want the width of parent has been also updated without explicit intervention

    import QtQuick 2.3
    import QtQuick.Controls 1.3
    
    Item {
        width: 300; height: 300
        Item
        {
            id: item
            width: element.width
            height: element.height
    
            Column
            {
                id: element
                Image
                {
                    id: image
                }
                Label
                {
                    id: label
                    text: "K"
                }
            }
    
            Component.onCompleted:
            {
                console.log ("Width item: " + item.width + " element: " + element.width + " image: " + image.width + " label: " + label.width)
                image.source = "img.bmp"
                console.log ("Width item: " + item.width + " element: " + element.width + " image: " + image.width + " label: " + label.width)
            }
        }
    }
    

    Console output shows that width of image is updated, but width of column (named "element") don't. How to do it automatically updated?

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xargs1
      wrote on 21 Aug 2015, 17:31 last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • C Offline
        C Offline
        chrisadams
        wrote on 24 Aug 2015, 07:28 last edited by
        #3

        You should be able to do this declaratively, by declaring either:

        width: image.width

        OR

        width: childrenRect.width

        for the "element" column.

        Note that this will "bind" the values. Binding is automatic in QML declarations. If you wish to bind from an imperative statement (ie, from within a JavaScript function) you can use:

        width = Qt.binding(function() { image.width });

        Hope this helps!

        1 Reply Last reply
        0

        3/3

        24 Aug 2015, 07:28

        • Login

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