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. Centering QGraphicsItem on position

Centering QGraphicsItem on position

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • P Offline
    P Offline
    Pippin
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    1
    • P Offline
      P Offline
      Pippin
      wrote on last edited by
      #2

      Well I think I need to bump this :S

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

        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.

        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