Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why does setTransform affect the boundingRect() ?
Forum Updated to NodeBB v4.3 + New Features

Why does setTransform affect the boundingRect() ?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.2k 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

    I set a transformation on a QGraphicsItem using setTransform.
    Suddenly, my previously fine boundingRect() no longer makes any sense.

    Please prove me wrong, but this is what I gathered from docs, source code and training documentation:

    The boundingRect() is given in the coordinate system of that item's parent, except that the position 0/0 is the item's position within the parent.
    This is also made clear by the fact how QGraphicsWidget implements it's boundingRect: It simply uses geometry().size(). Now the geometry() must be in parent coordinates (although the docs neglect to mention that), because "geometry() is equivalent to QRectF(pos(), size())" and since pos() must be in parent coordinates, it would not make any sense for size() to be in a different coordinate system.

    setTransform is supposed to affect the item's coordinate system, not the parent's coordinate system.

    Taken together, it simply does not make any sense for the boundingRect() to need any tweaks if I change the transformation of an item. Especially since QGraphicsWidget's implementation of boundingRect() breaks as soon as I change the transformation, this looks like a bug to me.

    And no, I am not using any "ItemIgnores*Transformations" flags.

    However, knowing I have been thinking about this too long, I might have dug my own logical hole. Can you see it?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      A transformation can do the following (just to name a few examples):

      • rotate an item
      • change item position
      • change item size
      • change item shape

      Now, out of those 4, three items change the overal shape of the item, and how much space it occupies on the screen. It seems natural to me, then, that the boudingRect should change after a transformation is applied.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        The size an item occupies in screen pixels might change due to a transformation, that does not necessarily mean the boundingRect must change.

        For example, if I render a rectangle of size 200x100 and give it the according boundingRect, the rectangle might actually occupy only 20x10 pixels at 10% zoom level. The item does not, and does not need to know about the zoom level.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          [quote author="Asperamanca" date="1408027022"]For example, if I render a rectangle of size 200x100 and give it the according boundingRect, the rectangle might actually occupy only 20x10 pixels at 10% zoom level. The item does not, and does not need to know about the zoom level.[/quote]

          Corect. But you are mixing a zoom level (which is about transforming the view/ scene) and setting a transformation on an item itelf. Those are 2 separate things. In case of zooming, you are right: there should be no need to change the bounding rect. But when you transform an item, the bounding rect will need an update.

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            [quote author="sierdzio" date="1408027456"] But when you transform an item, the bounding rect will need an update.[/quote]

            And why should it be necessary? Technically, it's no big deal for the GraphicsView framework to determine the actual boundindRect (in screen pixels) based on the information available. Again, it comes down to which coordinate system the boundingRect is defined in.
            Also, given you are right, why did nobody notice that the boundingRect-implementation of QGraphicsWidget makes no sense once you apply a transformation to the item itself?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Perhaps we both misunderstand something ;-)

              (Z(:^

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                Well, in fact, it's no big deal. I know how to write my code so it does what I want. It's just very frustrating that all the relevant places in the docs omit in which coordinate system important stuff is.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #8

                  Turns out, it is a big deal after all, because the alternatives introduce all kinds of complications.

                  Also, I have found some interesting points in the docs:

                  bq. An item's transformation does not affect its own local geometry; all geometry functions (e.g., contains(), update(), and all the mapping functions) still operate in local coordinates

                  and

                  bq. Although the item's shape can be arbitrary, the bounding rect is always rectangular, and it is unaffected by the items' transformation.

                  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