August 21, 2012

bluestreak bluestreak
Lab Rat
33 posts

QML Property Binding update does not propagate

 

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.

  1. Item{
  2.     id:navTab
  3.     property bool split: data.splitScreen
  4.     property double size: 1
  5.     Rectangle {
  6.          width: 100*navTab.size
  7.          height: 100*navTab.size
  8.          color: "black"
  9.          border.color: "lawngreen"
  10.          border.width: 5*navTab.size
  11.          Text{
  12.              anchors.centerIn: parent
  13.              text: "Info"
  14.              font.pointSize: 18*navTab.size
  15.              color: "white"
  16.          }
  17.          radius: 10*navTab.size
  18.     }
  19.     states: [
  20.         State{
  21.             name: "split"; when: split
  22.             PropertyChanges {
  23.                 target: navTab
  24.                 size: 1/2
  25.             }
  26.         }
  27.     ]
  28. }

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.

  1.     Text {
  2.         text: "HEADING"
  3.         font.pointSize: navTab.fontsize
  4.         color: "white"
  5.     }
  6.         State{
  7.             name: "split"; when: carData.splitScreen
  8.             PropertyChanges {
  9.                 target: navTab
  10.                 fontsize: 9
  11.             }
  12.         }

Also, trying to create a dependency on a f—unction doesn’t seem to work either

  1.     function getFontSize(){
  2.         return navTab.fontsize;
  3.     }
  4.          Text{
  5.              text: "Info"
  6.              font.pointSize: navTab.getFontSize()
  7.          }

3 replies

August 22, 2012

chriadam chriadam
Ant Farmer
181 posts

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:

  1. import QtQuick 2.0
  2.  
  3. Item {
  4.     id: root
  5.     width: 600
  6.     height: 600
  7.  
  8.     property double size: 50
  9.     function getSize() { return root.size; }
  10.  
  11.     Rectangle {
  12.         id: blueRect
  13.         anchors.left: parent.left
  14.         width: root.size * 2
  15.         height: root.size * 4
  16.         color: "blue"
  17.     }
  18.  
  19.     Rectangle {
  20.         id: redRect
  21.         anchors.right: parent.right
  22.         width: root.getSize() * 2
  23.         height: root.getSize() * 4
  24.         color: "red"
  25.     }
  26.  
  27.     Timer {
  28.         interval: 1000
  29.         repeat: true
  30.         running: true
  31.         onTriggered: if (root.size == 50) root.size = 100; else root.size = 50;
  32.     }
  33. }

August 22, 2012

kkoehne kkoehne
Ant Farmer
61 posts

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

  1. import QtQuick 1.1
  2.  
  3. Item {
  4.     id:navTab
  5.     property bool split: width < 300
  6.     property double size: 1
  7.     Rectangle {
  8.          width: 100*navTab.size
  9.          height: 100*navTab.size
  10.          color: "black"
  11.          border.color: "lawngreen"
  12.          border.width: 5*navTab.size
  13.          Text{
  14.              anchors.centerIn: parent
  15.              text: "Info"
  16.  
  17.              font.pointSize: 18*navTab.size
  18.              color: "white"
  19.          }
  20.          radius: 10*navTab.size
  21.     }
  22.     states: [
  23.         State{
  24.             name: "split"; when: split
  25.             PropertyChanges {
  26.                 target: navTab
  27.                 size: 1/2
  28.             }
  29.         }
  30.     ]
  31. }

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 :)

August 22, 2012

bluestreak bluestreak
Lab Rat
33 posts

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.

 
  ‹‹ Fail to get active focus on ListView enclosed in FocusScope after changing it’s visibility      QStringListModel doesn’t update ListView ››

You must log in to post a reply. Not a member yet? Register here!