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. using properties in calculations
Forum Updated to NodeBB v4.3 + New Features

using properties in calculations

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 391 Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    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:
    smallwells.PNG

    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:
    bigwells.PNG

    I omitted the derivation of cellHeight, but it works fine (for various sizes). What might I be doing wrong with the wellSizeRatio property?

    Thanks...

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by fcarney
      #2

      @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.

      C++ is a perfectly valid school of magic.

      mzimmersM 1 Reply Last reply
      2
      • fcarneyF fcarney

        @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.

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @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 square
        

        That'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!

        1 Reply Last reply
        2

        • Login

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