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. Getting the Axis aligned Bound Box of an item is has transformations (rotation, scaling,...)
Forum Updated to NodeBB v4.3 + New Features

Getting the Axis aligned Bound Box of an item is has transformations (rotation, scaling,...)

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 912 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.
  • F Offline
    F Offline
    Flamaros
    wrote on last edited by
    #1

    I need to find a way to retrieve the AABB of an item that works even if it has transformations applied.
    I thought anchors was always AA, but left can look to bottom with a rotation of -45 degrees.

    I need something precise to be able to place other elements correctly.

    I tried with a component but it's not really easy to implement and there is a lot of hacks without success.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Flamaros
      wrote on last edited by
      #2

      I got the solution, I just miss Rect are Axis Aligned so we can simply apply the item transformation to get the AABB :

      AABB.qml
      @
      import QtQuick 2.1

      Rectangle {
      id: aabb
      color: "#AAAAFF"

      property real   childrenRotation: {
          if (children.length)
              return children[0].rotation
          else
              return false
      }
      
      property real   childrenScaling: {
          if (children.length)
              return children[0].scale
          else
              return false
      }
      
      onChildrenRotationChanged: update()
      onChildrenScalingChanged: update()
      
      function    update()
      {
          var rect = mapFromItem(children[0], children[0].x, children[0].y, children[0].width, children[0].height)
          width = rect.width
          height = rect.height
      }
      

      }
      @

      main.qml (Center the child in the AABB component) :
      @
      import QtQuick 2.0

      Rectangle {
      width: 360
      height: 360
      AABB {
      anchors.centerIn: parent

          Text {
              text: qsTr("Hello World")
              anchors.centerIn: parent
              transformOrigin: Item.Center
      
              SequentialAnimation on rotation {
                  // Animations on properties start running by default
                  running: true
                  loops: Animation.Infinite // The animation is set to loop indefinitely
                  NumberAnimation { from: 0; to: 359; duration: 50000 }
              }
              SequentialAnimation on scale {
                  // Animations on properties start running by default
                  running: true
                  loops: Animation.Infinite // The animation is set to loop indefinitely
                  NumberAnimation { from: 0.25; to: 4; duration: 50000 }
              }
          }
      }
      MouseArea {
          anchors.fill: parent
          onClicked: {
              Qt.quit();
          }
      }
      

      }
      @

      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