Results 1 to 2 of 2

Thread: Qgraphicsitem parent/child paint problem.

  1. #1
    Join Date
    Jul 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Qgraphicsitem parent/child paint problem.

    Hi all,
    Suppose to have 2 items derived from qgraphicsitem, container and object, and suppose to override the object mouseReleaseEvent.
    I do this:
    Qt Code:
    1. IamInaContainer=false;
    2. if(!scene()->collidingItems(this).isEmpty()){
    3.  
    4. QList<QGraphicsItem*> lista_Ogge=scene()->collidingItems(this);
    5. for(int u=0;u<lista_Ogge.size();u++){
    6.  
    7. if((lista_Ogge.at(u))->type()==soa_container::Type){
    8. IamInaContainer=true;
    9. setParentItem(lista_Ogge.at(u));
    10. break;
    11. }
    12.  
    13. }
    14. }
    15. if(!IamInaContainer)setParentItem(0);
    To copy to clipboard, switch view to plain text mode 

    everythings is good , i'm able to move the object inside a container and then if i move container the object is moved right.Also i can move the object away from the container and setparent(0) work fine.

    The problem is the draw position. When i insert the object inside the container the object don't stay where i released the mouse button, but shift (apparently) by a random vector.
    Also when i drag the object away from container (suppose to move the object 50 pixel away the container) the object, after release, is drawn somewhere in the scene.

    Notice that if i comment out this line:
    Qt Code:
    1. //setParentItem(lista_Ogge.at(u));
    To copy to clipboard, switch view to plain text mode 

    Everythings is good about positioning, never got a random offset from release to draw point, but offcourse object is ever without parent.

    I think i missing sometimes about child/parent position.
    Thx in advice.

  2. #2
    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 parent/child paint problem.

    You need to calculate and set the new position of the item relative to the new parent's origin.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Paint QGraphicsItem problem
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2008, 18:18
  2. QT 4.4.0 Upgrade QPainter Problem
    By ChrisReath in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 15:25
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  4. Replies: 1
    Last Post: 26th December 2007, 10:58
  5. QGraphicsItem problem - how to save items info ??
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 12:17

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.