Centering QGraphicsItem on position



  • Hi,

    This problem initially surfaced here and @mrjj advised me to make a new thread for it, so here it comes (-:

    I'm using QPropertyAnimations to draw and translate QGraphicsPixmapItems from Point A to Point B. (Technically animations can't work on QGraphicsPixmapItems, since they aren't QObjects, so I had to create a class that inherits from both QObject and QGraphicsPixmapItem.)

    My problem is that Qt doesn't center the items it draws. For example, if the position of a given QGraphicsPixmapItem is [x, y], then [x, y] will match the top left corner of that QGraphicsPixmapItem, rather than its center. So when I'm translating one of these items from Point A to Point B via QPropertyAnimations, Qt is basically translating the top-left corner of that item all the way to Point B, rather than its center.

    I would like to fix that but I don't know how. I tried to set the TransformOriginPoint to the center of the item, but that didn't do. I've looked for options that would make Qt center the items it draws, but I couldn't find any. I -must- use animations, so I can't center the items myself.

    Could anybody help? Thanks in advance.



  • Well I think I need to bump this :S



  • Bumping isn't really good style. Unsolved threads are listed as such, and people will answer when and if they feel they have something to contribute.

    The easiest way to solve this is by creating your own QGraphicsItem (or QGraphicsObject) which draws a centered pixmap. You can either do this by painting a QPixmap yourself, or by wrapping a QGraphicsPixmapItem.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.