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. How can I reuse a QML Scale element to scale incrementally around changing origins?

How can I reuse a QML Scale element to scale incrementally around changing origins?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.9k 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.
  • C Offline
    C Offline
    cpbotha
    wrote on 29 Jun 2014, 18:52 last edited by
    #1

    Dear all,

    I've also posted this question on Stack Overflow: http://stackoverflow.com/questions/24478653/how-to-use-qml-scale-element-for-incremental-scaling-with-different-origin -- if you prefer that you can always respond there.

    In any case, I'm trying to use a QML Scale Element to perform view scaling around a point clicked by the user. The user can change the zoom point by clicking elsewhere. I'm using a QML Scale Element and setting its origin based on the user's click position.

    In the following minimal example, this works when you click your first point (try the center of the blue rectangle at top left). However, when you click on another point (try the center of the red rectangle) the zoom causes a translation jump. If you now click again on that second point (at its new position), zooming works as expected, until you want to zoom around a new point again. What am I doing wrong?

    @
    import QtQuick 2.2
    import QtQuick.Controls 1.1

    ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {
        x: 100
        y: 100
        width: 300
        height: 300
    
        transform: Scale {
            id: tform
        }
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                console.log(mouse.x + " " + mouse.y)
                tform.xScale += 0.5
                tform.yScale += 0.5
                tform.origin.x = mouse.x
                tform.origin.y = mouse.y
            }
        }
    
        Rectangle {
            x: 50
            y: 50
            width: 50
            height: 50
            color: "blue"
        }
    
        Rectangle {
            x: 100
            y: 100
            width: 50
            height: 50
            color: "red"
        }
    
    }
    

    }
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 29 Jun 2014, 19:11 last edited by
      #2

      You are changing the scale before updating the origin.

      And, as a side note: you can use "scale" property instead of "transform".

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cpbotha
        wrote on 29 Jun 2014, 19:26 last edited by
        #3
        1. Tried both ways, no difference.
        2. The documentation states to do it this way (i.e. with a Scale element and NOT the scale property), exactly because I need to scale around the user-clicked zoom point.

        Any other ideas? :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 29 Jun 2014, 19:29 last edited by
          #4

          Ah sure, I somehow partially forgot about the zoom point thing ;P No, I don't have more ideas.

          (Z(:^

          1 Reply Last reply
          0

          3/4

          29 Jun 2014, 19:26

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved