using properties in calculations
-
Hi all -
I have a view that uses this code:
Item { id: root property double cellHeight: <something> property double wellSizeRatio: 0.5 Grid { Repeater { id: wellsRepeater delegate: Rectangle { height: cellHeight width: height color: 'white' border.color: 'black' Rectangle { anchors.centerIn: parent height: cellHeight * 0.5 width: height radius: height / 2 }This (correctly) produces this:
If I try to replace the hard-coded 0.5 in the Rectangle as follows:
Item { id: root property double cellHeight: <something> property double wellSizeRatio: 0.5 Grid { Repeater { id: wellsRepeater delegate: Rectangle { height: cellHeight width: height color: 'white' border.color: 'black' Rectangle { anchors.centerIn: parent height: cellHeight * wellSizeRatio width: height radius: height / 2 }It doesn't work:
I omitted the derivation of cellHeight, but it works fine (for various sizes). What might I be doing wrong with the wellSizeRatio property?
Thanks...
-
@mzimmers said in using properties in calculations:
wellSizeRatio
Is wellSizeRatio italicized in the editor? That would indicate it sees the variable. If no "root" object is not the root of your qml object then you may need to qualify wellSizeRatio like this: root.wellSizeRatio. Does wellSizeRatio get changed anywhere? Try making it a readonly to see if something turns red somewhere.
-
@mzimmers said in using properties in calculations:
wellSizeRatio
Is wellSizeRatio italicized in the editor? That would indicate it sees the variable. If no "root" object is not the root of your qml object then you may need to qualify wellSizeRatio like this: root.wellSizeRatio. Does wellSizeRatio get changed anywhere? Try making it a readonly to see if something turns red somewhere.
@fcarney your suggestion of making wellSizeRatio readonly led me to find the problem, which was that it was getting overridden in a calling file:
WellPlate { id: theWells wellSizeRatio: 0.8 // circle height is smaller than grid squareThat's a pretty good debugging tip to keep in mind: if a property seems to be changing out from under you, check the callers for possible "overrides."
Thanks for the help!