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. [SOLVED] How to fix anchor/clipping problems when scaling a GridView
QtWS25 Last Chance

[SOLVED] How to fix anchor/clipping problems when scaling a GridView

Scheduled Pinned Locked Moved QML and Qt Quick
gridviewscaleflickable
5 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.
  • P Offline
    P Offline
    pholz
    wrote on 29 Apr 2015, 16:00 last edited by pholz 5 May 2015, 16:23
    #1

    I implemented a "zoom" feature by allowing to adjust the scale property of a GridView that wraps at the right edge:

    GridView {
      //...
      scale: zoomLevel
      transformOrigin: Item.TopLeft
      anchors.top: commandArea.bottom
      anchors.left: parent.left
      anchors.right: parent.right
      anchors.bottom: statusArea.top
     }
    

    However, although the anchors are constant, when I zoom in, the content exceeds the right border and when I zoom out, the content is clipped above the bottom border.

    I was able to fix the issues using the following properties:

    anchors.rightMargin: (scale - 1.0) * width
    anchors.bottomMargin: -(height * (1.0 - scale))
    

    However, I get "binding loop" errors related to these two lines in the console every time I adjust the zoom level. While it seems to work anyway, the errors indicate that it's a bit of a hack... Is there a better way to do this? If not, can I just ignore the errors?

    P 1 Reply Last reply 29 Apr 2015, 16:38
    0
    • P pholz
      29 Apr 2015, 16:00

      I implemented a "zoom" feature by allowing to adjust the scale property of a GridView that wraps at the right edge:

      GridView {
        //...
        scale: zoomLevel
        transformOrigin: Item.TopLeft
        anchors.top: commandArea.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: statusArea.top
       }
      

      However, although the anchors are constant, when I zoom in, the content exceeds the right border and when I zoom out, the content is clipped above the bottom border.

      I was able to fix the issues using the following properties:

      anchors.rightMargin: (scale - 1.0) * width
      anchors.bottomMargin: -(height * (1.0 - scale))
      

      However, I get "binding loop" errors related to these two lines in the console every time I adjust the zoom level. While it seems to work anyway, the errors indicate that it's a bit of a hack... Is there a better way to do this? If not, can I just ignore the errors?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 29 Apr 2015, 16:38 last edited by
      #2

      Hi @pholz,
      I suspect this is because the width of GridView is binded to rightMargin (right side spacing) of the GridView itself. So when the width of GridView changes it affects the rightMargin which in turn will affect the width of GridView (it will become thinner) and thus this goes on (loop).

      157

      P 1 Reply Last reply 4 May 2015, 09:38
      0
      • P p3c0
        29 Apr 2015, 16:38

        Hi @pholz,
        I suspect this is because the width of GridView is binded to rightMargin (right side spacing) of the GridView itself. So when the width of GridView changes it affects the rightMargin which in turn will affect the width of GridView (it will become thinner) and thus this goes on (loop).

        P Offline
        P Offline
        pholz
        wrote on 4 May 2015, 09:38 last edited by
        #3

        @p3c0 I see. Any ideas what to use instead?

        P 1 Reply Last reply 4 May 2015, 10:15
        0
        • P pholz
          4 May 2015, 09:38

          @p3c0 I see. Any ideas what to use instead?

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 4 May 2015, 10:15 last edited by
          #4

          @pholz Try assigning using = instead of binding.

          157

          P 1 Reply Last reply 5 May 2015, 16:20
          1
          • P p3c0
            4 May 2015, 10:15

            @pholz Try assigning using = instead of binding.

            P Offline
            P Offline
            pholz
            wrote on 5 May 2015, 16:20 last edited by
            #5

            @p3c0 seems to work, thanks!

            new code:

            onScaleChanged: {
                anchors.rightMargin = (scale - 1.0) * width;
                anchors.bottomMargin = -(height * (1.0 - scale));
            }
            
            1 Reply Last reply
            0

            3/5

            4 May 2015, 09:38

            • Login

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