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. QML Property Binding update does not propagate
Forum Updated to NodeBB v4.3 + New Features

QML Property Binding update does not propagate

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 3.3k Views 1 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.
  • B Offline
    B Offline
    bluestreak
    wrote on last edited by
    #1

    Hi,

    I have a QML property size, which I am trying to use to change many of my attributes to half size when I reach a split screen state. However, when I update the size property in this state, the reduction in size does not propogate to things such as font size which depend upon it.

    @
    Item{
    id:navTab
    property bool split: data.splitScreen
    property double size: 1
    Rectangle {
    width: 100navTab.size
    height: 100
    navTab.size
    color: "black"
    border.color: "lawngreen"
    border.width: 5navTab.size
    Text{
    anchors.centerIn: parent
    text: "Info"
    font.pointSize: 18
    navTab.size
    color: "white"
    }
    radius: 10*navTab.size
    }
    states: [
    State{
    name: "split"; when: split
    PropertyChanges {
    target: navTab
    size: 1/2
    }
    }
    ]
    }
    @
    What am I missing about bindings here, which will allow me to do this?

    I have also tried simplifying this and using a fontsize property, but even this alone does not propagate when updated.
    @
    Text {
    text: "HEADING"
    font.pointSize: navTab.fontsize
    color: "white"
    }
    State{
    name: "split"; when: carData.splitScreen
    PropertyChanges {
    target: navTab
    fontsize: 9
    }
    }
    @

    Also, trying to create a dependency on a f--unction doesn't seem to work either
    @
    function getFontSize(){
    return navTab.fontsize;
    }
    Text{
    text: "Info"
    font.pointSize: navTab.getFontSize()
    }
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chriadam
      wrote on last edited by
      #2

      You may need to give more information (which platform are you on, etc).

      The following code demonstrates that both bindings to properties directly, and bindings which involve calls to functions which themselves access proeprties, both cause changes to be propagated:

      @
      import QtQuick 2.0

      Item {
      id: root
      width: 600
      height: 600

      property double size: 50
      function getSize() { return root.size; }
      
      Rectangle {
          id: blueRect
          anchors.left: parent.left
          width: root.size * 2
          height: root.size * 4
          color: "blue"
      }
      
      Rectangle {
          id: redRect
          anchors.right: parent.right
          width: root.getSize() * 2
          height: root.getSize() * 4
          color: "red"
      }
      
      Timer {
          interval: 1000
          repeat: true
          running: true
          onTriggered: if (root.size == 50) root.size = 100; else root.size = 50;
      }
      

      }
      @

      1 Reply Last reply
      0
      • kkoehneK Offline
        kkoehneK Offline
        kkoehne
        Moderators
        wrote on last edited by
        #3

        I made minimal changes to your example to make it self-contained:

        @
        import QtQuick 1.1

        Item {
        id:navTab
        property bool split: width < 300
        property double size: 1
        Rectangle {
        width: 100navTab.size
        height: 100
        navTab.size
        color: "black"
        border.color: "lawngreen"
        border.width: 5*navTab.size
        Text{
        anchors.centerIn: parent
        text: "Info"

                 font.pointSize: 18*navTab.size
                 color: "white"
             }
             radius: 10*navTab.size
        }
        states: [
            State{
                name: "split"; when: split
                PropertyChanges {
                    target: navTab
                    size: 1/2
                }
            }
        ]
        

        }
        @

        All bindings are evaluated for me as expected. So either

        • you're using another Qt version with a bug
        • your logic in data.splitScreen is faulty, or
        • your example doesn't really show the deficiency that you've been talking about :)

        Director R&D, The Qt Company

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bluestreak
          wrote on last edited by
          #4

          Hi,

          Thank you both for your kind help, I appreciate the time you took to examine my problem. You were correct in that the problem was with data.splitScreen. I had assumed it was working, since I was getting split screens, but I was actually creating the splitScreens within my main QML with a property, which I had not reset to depend on data.SplitScreen when I modified it. Thanks again for your help.

          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