Results 1 to 7 of 7

Thread: QGraphicsItem position

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default QGraphicsItem position

    Hi,

    I have an QGraphicsItem in which I have some other QGraphicsItem's. What I want to ask is, it seems(I printed the pos.x and pos.y values) the child items has automatically centered at their parent item's center. Is it true?

    Nevertheless, one of my item is;

    myItem.setRect(-7,-7,10,10);

    and I once set the position of my item to 0,0 it does not seen it is on the center of it's parent item. Is that something wrong? or Is that for the reason that item's coordinates can only be integers?

    Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItem position

    Technically, QGraphicsRectItem::setRect() does not affect the position of the item. Visually it does, because it affects the bounding rect of the item.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem position

    Hi,

    Well ok..up to now, I understood that the position of an item can be changed by setPos(..).

    AND just like you said, if I make QGraphicsItem.setRect(-7,-7,10,10) does it seems different than if I make QGraphicsItem.setRect(-5,-5,10,10) ? And Why?

    For example, for QGraphicsItem.setRect(-5,-5,10,10), the rect drawn symmetrical around the
    item's origin(4 equal subrectangles) but,
    for QGraphicsItem.setRect(-7,-7,10,10), the rect drawn would not be symmetrical. Does it explain thw Why above?

    Hope it's clear, Regards

  4. #4
    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: QGraphicsItem position

    If you don't use setPos() then the item's origin is aligned to its parent's origin therefore a rectangle beginning at (-7,-7) will be two units more to the left and up than the item beginning at (-5,-5).

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem position

    So I'm right.


    Regards.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItem position

    I was talking about the difference between QGraphicsItem::setPos() and QGraphicsRectItem::setRect(). Of course QGraphicsRectItem::setRect() affects the "visual position" of the item, but it won't change QGraphicsItem:os.
    J-P Nurmi

  7. #7
    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: QGraphicsItem position

    By the way, item coordinates can be real values, not only integers.

Similar Threads

  1. QTextEdit restore cursor position
    By artur231 in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2014, 22:02
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. Replies: 2
    Last Post: 28th June 2008, 16:31
  4. QGraphicsView: Dialog Position Doubt
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 17:48

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.