Results 1 to 3 of 3

Thread: how to hide QgraphicsItem !!!

  1. #1
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to hide QgraphicsItem !!!

    Hi..
    I have a problem of how to use correcty the QGraphicsItemGroup ..
    well. my application is about zooming on a map .. so depending on the zoom I should display or hide some details..
    for example to put the names of cities after zooming I used:

    Qt Code:
    1. void myview::zoomingin(){
    2.  
    3. for (int i=0;i<5;i++){
    4. QGraphicsTextItem * txt=new QGraphicsTextItem(citiesName[i]);
    5. txt->setPos(citiesX[i],citiesY[i]);
    6. scene->addItem(txt);
    7. group->addToGroup(txt);
    8. }
    9. graphicsView->scale(1.2,1.2);
    10. }
    To copy to clipboard, switch view to plain text mode 
    >> citiesName,citiesX,citiesY are QList containin' the names and coordonates of each citie..

    then I should hide them when we zoom out .. I try to used:
    Qt Code:
    1. void myview::zoomingout(){
    2.  
    3. scene->destroyItemGroup(group);
    4.  
    5. graphicsView->scale(1/1.2,1/1.2);
    6. }
    To copy to clipboard, switch view to plain text mode 

    but it doesnt work .. nd when the group became empty it stucks!!

    plz if someOne have a idea !!!!!!!!!!!!!!!!!!!!!!
    Last edited by jpn; 24th May 2008 at 22:07. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to hide QgraphicsItem !!!

    Hello peace_comp, here's a quote from the docs about destroyItemGroup:

    void QGraphicsScene::destroyItemGroup ( QGraphicsItemGroup * group )
    Reparents all items in group to group's parent item, then removes group from the scene, and finally deletes it. The items' positions and transformations are mapped from the group to the group's parent.
    So it sounds like you'll need to delete each label individually. If you want to keep using an ItemGroup, just loop through its childItems() and delete them individually before removing the group.

    Hope this helps,

    Wesley
    ImageRocket - My Qt4-based image editing program
    Project Page / Screenshots / Source

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to hide QgraphicsItem !!!

    well, see the 40000 chip demo,,, they hide details depending on zoom level, It might help u.

    Also based on zoom level, u can emit a signal from the scene to some handler class. In the handler class, hide the graphic items u want to hide

Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 22:24
  2. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  3. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  4. Snap-to grid on QGraphicsItem
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 28th April 2008, 16:22
  5. model/view, can't hide row/col
    By grellsworth in forum Qt Programming
    Replies: 7
    Last Post: 17th September 2007, 14:21

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.