Results 1 to 12 of 12

Thread: QGraphicsItem meaning of pos(), scenePos()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem meaning of pos(), scenePos()

    Program I develop is interactive editor. So, setPos() and rotate() are used frequently in the order which user decides.

    By sceneBoundingRect() I detect item position in scene relating to other items to estimate correct user's interactive move by mouse.

    So, how to setPos() correctly after rotating item around its center? setPos() I mean to set item position programmatically.

    Should I decrease value by item->transform().dx() and item->transform().dy() ?
    Also it is necessary to take care of signs (decrease or increase)

    In my case items do not have parents.
    Last edited by nicolas1; 6th October 2008 at 08:01.

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

    Default Re: QGraphicsItem meaning of pos(), scenePos()

    Quote Originally Posted by nicolas1 View Post
    Program I develop is interactive editor. So, setPos() and rotate() are used frequently in the order which user decides.
    But how is that related to other items on the scene?

    By sceneBoundingRect() I detect item position in scene relating to other items to estimate correct user's interactive move by mouse.
    But why? If you want scene coordinates, handle the event in the scene and not in the item. Anyway I see no point in knowing scene coordinates while handling mouse move.

    So, how to setPos() correctly after rotating item around its center? setPos() I mean to set item position programmatically.

    Should I decrease value by item->transform().dx() and item->transform().dy() ?
    Also it is necessary to take care of signs (decrease or increase)
    You shouldn't need to do anything. Can you provide a snippet of code (or better yet a small compilable example) to show us what you are trying to do? Basically if we want to correct item position, we tend to do it in itemChange() not in mouse move events.

  3. #3
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem meaning of pos(), scenePos()

    For example, one item is rectangular and second item (picture) is inside.
    User press the button and picture item needs to be enlarged but not more than rectangular item. That's why I need to correct item position and size.

    Also item can be rotated, also picture item can be enlarged but no more then rectangular item.

    I can get rectangulat item position and size by sceneBoundingRect().

    Maybe thaere is another way to do my task...

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

    Default Re: QGraphicsItem meaning of pos(), scenePos()

    Quote Originally Posted by nicolas1 View Post
    For example, one item is rectangular and second item (picture) is inside.
    So one should be child of the other and the problem disappears.

    User press the button and picture item needs to be enlarged but not more than rectangular item. That's why I need to correct item position and size.
    That you can control from within itemChange(), even without parent-child relationship between the items using different collision modes.

    Also note a difference between boundingRect and shape.

  5. #5
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem meaning of pos(), scenePos()

    I need to correct picture item position and size according to rect item and some rule.

    When picture item's transform is identity, rect item's sceneBoundingRect() and picture item's sceneBoundingRect() is used well to calculate coordinate for setPos() and changing size.

    When picture item is rotated (transform has dx, dy and rotation) it is impossible to use setPos() to rotated picture item, because it will result in different item position.
    Different position is result of summation of item's d_ptr->pos() and item's transform.

    How to calculate right coordinate, based on sceneBoundingRect() or maybe some other members, for setPos() of rotated picture item?

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

    Default Re: QGraphicsItem meaning of pos(), scenePos()

    Quote Originally Posted by nicolas1 View Post
    When picture item is rotated (transform has dx, dy and rotation) it is impossible to use setPos() to rotated picture item, because it will result in different item position.
    Different position is result of summation of item's d_ptr->pos() and item's transform.
    If you only use scaling and rotating and the origin is in the middle of the item, setPos shoud be transparent to them. Could you provide a minimal compilable example reproducing your problem?

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31

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
  •  
Qt is a trademark of The Qt Company.