Results 1 to 10 of 10

Thread: transform() vs pos() for QGraphicsItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: transform() vs pos() for QGraphicsItem

    It is not just setPos(), but also setScale() and setRotation(), and setTransformations(), that do not affect the separate transform() matrix. (e.g. transform() returns the same matrix before and after a call to setScale().)

    I won't argue which is the best approach for the API, but I will say that the Qt approach is not conventional: most graphics programming texts approach use a single transform matrix that a rotation operation would change.

    And the Qt documentation must be read VERY carefully. For example: "The scale is combined with the item's rotation(), transform() and transformations() to map the item's coordinate system to the parent item." Why doesn't it mention pos()? Then you should follow the link to "Transformations" to learn what "combine" means. And "scale a transformation" is QTransform.scale(), not the same thing as calling "setScale()" on a graphic item. QTransform.scale() is a verb setter, QGraphicsItem.scale() is a noun getter. QTransform is separate from QGraphicsTransform. transform() is not the same as transformations(), even though both are noun getters with too similar names.

    This discussion is related to how to serialize a QGraphicsItem. Do you need to serialize (pos(), scale(), rotation(), transform(), transformations()) or can you somehow get a single matrix representing all of those?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: transform() vs pos() for QGraphicsItem

    Quote Originally Posted by bootchk View Post
    It is not just setPos(), but also setScale() and setRotation(), and setTransformations(), that do not affect the separate transform() matrix. (e.g. transform() returns the same matrix before and after a call to setScale().)
    The methods you mention were introduced in Qt 4.6 thus the discussion in this thread does not take them into consideration.

    I won't argue which is the best approach for the API, but I will say that the Qt approach is not conventional: most graphics programming texts approach use a single transform matrix that a rotation operation would change.
    Those methods were added to QGraphicsItem as a convenience. Therefore both "old" and "new" ways exist to operate on the item.

    Why doesn't it mention pos()?
    Because pos() is not part of the "transformation".

    Then you should follow the link to "Transformations" to learn what "combine" means. And "scale a transformation" is QTransform.scale(), not the same thing as calling "setScale()" on a graphic item. QTransform.scale() is a verb setter, QGraphicsItem.scale() is a noun getter. QTransform is separate from QGraphicsTransform. transform() is not the same as transformations(), even though both are noun getters with too similar names.
    Again, some classes and methods are a later addition to Qt. Since you can't remove something that's already defined in an earlier release, some functionality is "doubled".

    This discussion is related to how to serialize a QGraphicsItem. Do you need to serialize (pos(), scale(), rotation(), transform(), transformations()) or can you somehow get a single matrix representing all of those?
    The attributes you mention are not part of the object definition thus this is not about serializing the item but rather the scene (as in getting a snapshot of current mappings of items in the scene). There is no built-in mechanism for that, you need to query all the attributes you are interested in on your own.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Where to apply transform? iterm or QPainter?
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 08:40
  2. Replies: 1
    Last Post: 22nd August 2008, 09:12
  3. Smooth pixmap transform in QGraphicsView problem
    By spud in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2007, 16:47

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.