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. Prevent overlap in Column with scaled
QtWS25 Last Chance

Prevent overlap in Column with scaled

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

    I have a need to use scale with one item in a Column. I cannot figure out how to eliminate the overlap between the two items. Any ideas? Thanks.

    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Column {
            anchors.centerIn: parent
            Rectangle {
                id: topRect
                color: "red"
                height: topText.implicitHeight
                width: topText.implicitWidth
                scale: 3
                Text {
                    id: topText
                    text: "This should not overlap"
                }
            }
            Rectangle {
                id: botRect
                height: 50
                width: 50
                color: "blue"
            }
        }
    }
    
    1 Reply Last reply
    0
    • L Offline
      L Offline
      lemons
      wrote on last edited by lemons
      #2

      The issue is that the column does not know about the rendered height of the item if you use scale.
      The height property remains the same, as otherwise the scale would scale the new height of the item.

      If you want to stick with scale, you could do something like this:

      Window {
          width: 400
          height: 680
          visible: true
      
          Column {
              anchors.centerIn: parent
      
              // add a wrapper for scaleable item
              Item {
                  anchors.horizontalCenter: parent.horizontalCenter
                  // set height and width to the scaled height and width of child
                  height: topRect.height * topRect.scale
                  width: topRect.width * topRect.scale
                  Rectangle {
                      id: topRect
                      color: "red"
                      height: 100
                      width: 100
                      scale: 3
                      // add transformOrigin top left, to scale to the lower right
                      // this way the scaled item will fill the wrapper item
                      transformOrigin: Item.TopLeft
                  }
              }
              Rectangle {
                  id: botRect
                  // only for better visualizing this item is right below the scaled one
                  anchors.horizontalCenter: parent.horizontalCenter
                  height: 100
                  width: 100
                  color: "blue"
              }
          }
      
          // just for testing
          Button {
              anchors.bottom: parent.bottom
              anchors.horizontalCenter: parent.horizontalCenter
              text: "Toggle Scale Change"
              onClicked: {
                  topRect.scale = topRect.scale === 1 ? 3 : 1
              }
          }
      }
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mlibu
        wrote on last edited by Mlibu
        #3

        Thank you. Answer was so simple. I'm still getting used to the flexibility and power of binding to properties.

        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