Results 1 to 3 of 3

Thread: [Solved]How to avoid setParentItem() from changing the item position?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Question [Solved]How to avoid setParentItem() from changing the item position?

    Hi,
    i'm using QGraphicsItem and some animations, i have a problem when i change the parent of an item because also it's position is changed. That's due to the fact that the position is related to the parent position, so i tried this:

    item->setPos(item->mapToItem(new_parent, item->pos());
    item->setParentItem(new_parent);

    but it seams like setParentItem occurs before setPos() and it updates the scene with the item in the wrong position.

    The only solution i found is to block all scene signals, set the parent , set the position, unlock the signals and update:

    QPointF position = item->pos();
    scene()->blocksignals(true);
    item->setPos(item->mapToItem(new_parent, item->pos());
    item->setParentItem(new_parent);
    scene()->blocksignals(false);

    that does the job but i'm looking for something more elegant than block all signals, also because i have other items on the scene and that would block their signal as well.

    Any suggestion?!?

    Thanks.
    Last edited by Dr.Poldo; 12th June 2009 at 11:59. Reason: updated contents

Similar Threads

  1. Graphics item position after drag
    By Miihkali in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2009, 11:01
  2. position of an item in a QStringList
    By jaca in forum Newbie
    Replies: 4
    Last Post: 29th May 2008, 06:49
  3. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 08:09
  4. Replies: 3
    Last Post: 12th April 2006, 10:35
  5. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 02:34

Tags for this Thread

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.