Change anchors conditionally?



  • I try to set anchors.right conditionally, but it does not work - it stays attached to startLine.left even as startsAtLowerBoundary changes. Why?

    I think I have eliminated that the problem could be because of anything else

    • I can see in the console logs that value is changed as expected.

    • When I hard code anchors.right: undefined I can see that the layout is as I would expect.

      Rectangle {
        property bool startsAtLowerBoundary: ui.selectionModel.startsAtLowerBoundary
      
        onStartsAtLowerBoundaryChanged: {
          console.log(startsAtLowerBoundary)
        }
      
        anchors.right: startsAtLowerBoundary ? startLine.left : undefined
        ...
      }

  • Moderators

    It should work... perhaps after removing the anchor the item "just happens" to remain in the same place? I mean, QML engine has no reason to move it somewhere else because an anchor is only detached, and not attached somewhere else.

    Another solution: use AnchorChanges, it would start working.



  • Bingo!

    Setting the anchor to undefined after having set a value previously does not produce the same result as setting anchor to undefined initially. I didn't consider that possibility.

    Thanks for the help!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.