Results 1 to 8 of 8

Thread: QGraphicsScene item positioning

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QGraphicsScene item positioning

    How do I mange QGraphicsScene's items position? Everytime I add a new item on my scene it gets centralized.Why does it do that?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsScene item positioning

    Quote Originally Posted by been_1990 View Post
    How do I mange QGraphicsScene's items position?
    use QGraphicsItem::setPos()
    Everytime I add a new item on my scene it gets centralized.Why does it do that?
    The item must be positioned anywhere, but that's no problem where since you have to arrange the items in the screen by yourself using the above mentioned function.

  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsScene item positioning

    This is how I'm adding the pixmap:
    Qt Code:
    1. scene->addItem(new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Normal,QIcon::On)));
    To copy to clipboard, switch view to plain text mode 
    How do I set its position if there was no name given to the QGraphicsPixmapItem?

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene item positioning

    you have to save the item in a member pointer or other global pointer... ther are other ways like findItem but that would be unecessary slow

  5. #5
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene item positioning

    you can rewrite this in following way:
    Qt Code:
    1. QGrphicsPixmapItem* item = new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Normal,QIcon::On);
    2. item->setPos(100, 100);
    3. scene->addItem(item);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsScene item positioning

    Wont things mess up if I continually call a function with
    Qt Code:
    1. QGrphicsPixmapItem* item = new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Normal,QIcon::On);
    2. item->setPos(100, 100);
    3. scene->addItem(item);
    To copy to clipboard, switch view to plain text mode 
    ?

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsScene item positioning

    Quote Originally Posted by been_1990 View Post
    Wont things mess up if I continually call a function with
    Qt Code:
    1. QGrphicsPixmapItem* item = new QGraphicsPixmapItem(tempIcon.pixmap(100,QIcon::Normal,QIcon::On);
    2. item->setPos(100, 100);
    3. scene->addItem(item);
    To copy to clipboard, switch view to plain text mode 
    ?
    Yes of course, but as said, you have to take care yourself for the arrangement of the items in the scene. (Or you could use QGraphicsLinearLayout)

  8. #8
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsScene item positioning

    Does QGraphicsLinearLayout automatically arrange the QGraphicsScene items in rows? Like
    Qt Code:
    1. 0 0 0 0 0 0 0 0
    2. 0 0 0 0 0 0 0 0
    3. 0 0 0 0 0 0 0 0
    4. 0 0 0 0 0 0 0 0
    5. 0 0 0 0 0 0 0 0
    6. 0 0 0 0 0 0 0 0
    To copy to clipboard, switch view to plain text mode 
    If it does, how do I implement it? Do I just add the scenes items to a QGraphicLinear layout? Does it also modify the height and width of the item if requested?

Similar Threads

  1. problem in positioning item in QGraphicsScene()
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 8th May 2009, 07:41
  2. positioning toolbar item
    By wagmare in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 16:32
  3. Replies: 2
    Last Post: 1st August 2008, 17:58
  4. Replies: 3
    Last Post: 4th April 2008, 20:51
  5. QWidget item in QGraphicsScene
    By IUnknown in forum Qt Programming
    Replies: 4
    Last Post: 4th November 2006, 01:05

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.