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. Change anchors conditionally?
Forum Updated to NodeBB v4.3 + New Features

Change anchors conditionally?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.6k 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.
  • P Offline
    P Offline
    pokemonsrqt
    wrote on last edited by pokemonsrqt
    #1

    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
        ...
      }
      
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      3
      • P Offline
        P Offline
        pokemonsrqt
        wrote on last edited by
        #3

        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!

        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