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 to get aggregated scaling factor for QML items?
Forum Updated to NodeBB v4.3 + New Features

How to get aggregated scaling factor for QML items?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 156 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    The effect of "scaling" a QML item aggregates, i.e. if an item's parent is scaled to 200 %, the item will also appear at 200 % scale.
    Is there an easy way to get the aggregated scaling factor for an item?

    Use case: My item opens a popup. The popup should use the same scaling as the item. Since the popup does not belong into the same item tree, it does not "inherit" the scaling automatically.

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by GrecKo
      #2

      Can you assume only the direct parent will have its scale set and bind the popup's scale to it?
      If you instead need to support a recursive item tree you could do it like that:

      property real aggregatedScale: {
          let parent = popup.parent;
          let scale = 1;
          while (parent) {
              scale *= parent.scale;
              parent = parent.parent;
         }
         return scale;
      }
      
      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by Asperamanca
        #3

        Thanks for your reply. I should have been more specific in my question: I know how to write it myself, I was looking for an existing function that already gives the that, akin to QGraphicsItem::sceneTransform.

        Because how would you expose such a function to QML, so you have it available globally, for all items? I guess that would mean something like a singleton object.

        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