Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-30772

Add support of anchors for reparenting operation (reevaluate anchors on ParentChange operation)

    XMLWordPrintable

Details

    Description

      Reparenting (ParentChange) only supports absolute element coordinates. It would be useful if reparenting would support/respect anchors as well, since anchors is a much cleaner way to specify relative positions.

      Currently, due to limitations of the ParentChange operation, anchors are completely ignored and the following code doesn't work as some would expect (the blueRect jumps down on reparenting). This happens because anchors are not reevaluated after ParentChange and since x/y coordinates of the blueRect become relative to the redRect instead of the topItem:

      Item {
          id: topItem
          width: 200; height: 200
       
          Rectangle {
              id: redRect
              clip: true
              width: 100; height: 100
              x: 20
              y: 20
              color: "red"
          }
       
          Rectangle {
              id: blueRect
              width: 50; height: 50
              color: "blue"
              anchors { top: redRect.top; left: redRect.right }
       
              states: State {
                  name: "reparented"
                  AnchorChanges   { target: blueRect; anchors.left: redRect.left; }
              }
       
              transitions: Transition {
                  SequentialAnimation{
                      AnchorAnimation { duration: 1000 }
                      ScriptAction{ script: blueRect.parent = redRect }
                  }
              }
       
              MouseArea {
                  anchors.fill: parent;
                  onClicked: blueRect.state = "reparented"
              }
          }
      }
      

      It would be cleaner/better/useful if reparenting would trigger anchors reevaluation if anchors were specified. (See also comments to QTBUG-30723)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            aalpert Alan Alpert
            maxus Maxim Makhinya
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes