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

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

Scheduled Pinned Locked Moved QML and Qt Quick
gridviewscaleflickable
5 Posts 2 Posters 2.0k 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 last edited by pholz
    #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?

    p3c0P 1 Reply Last reply
    0
    • P pholz

      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?

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on 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
      0
      • p3c0P p3c0

        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 last edited by
        #3

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

        p3c0P 1 Reply Last reply
        0
        • P pholz

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

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @pholz Try assigning using = instead of binding.

          157

          P 1 Reply Last reply
          1
          • p3c0P p3c0

            @pholz Try assigning using = instead of binding.

            P Offline
            P Offline
            pholz
            wrote on 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

            • Login

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