Results 1 to 3 of 3

Thread: Removing a QGraphicsPixmapItem from a scene

  1. #1
    Join Date
    Jul 2008
    Posts
    18
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Cool Removing a QGraphicsPixmapItem from a scene

    Hi folks

    Ok im wondering if anyone out there can give me an idea on how i can remove a QGraphicsPixmapItem from my scene after the animation is complete. I need to move a few pixmaps across the scene from left to right and have only been doing qt4 for about a month still new to this. Anyhow so far i have an image that can scroll across then after it reaches the right side and is no longer visable i need to call removeItem() but im not sure what to check to see where this item is on the scene, i want it to look like it scrolled off the scene. Also i may have more then 1 item on the scene so thats why i used QGraphicsItemAnimation in case i need to speed or slow down items. Here is some test code, just replace the testimage with any jpg. Any help would be appreciated. Here is the code, very short.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main (int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. QPixmap testimage("/images/car.jpg");
    7. QGraphicsPixmapItem* item = new QGraphicsPixmapItem(testimage);
    8. QTimeLine *timer = new QTimeLine(15000);
    9.  
    10. timer->setFrameRange(0, 100);
    11. timer->setLoopCount(1);
    12.  
    13. animation->setItem(item);
    14. animation->setTimeLine(timer);
    15.  
    16. animation->setPosAt(0.0, QPoint(-800, 100));
    17. animation->setPosAt(0.10, QPoint(-600, 100));
    18. animation->setPosAt(0.15, QPoint(-400, 100));
    19. animation->setPosAt(0.20, QPoint(-100, 100));
    20. animation->setPosAt(0.25, QPoint(-50, 100));
    21. animation->setPosAt(0.50, QPoint(600, 100));
    22.  
    23. scene->setSceneRect(0, 0, 250, 250);
    24. scene->addItem(item);
    25.  
    26. QGraphicsView *view = new QGraphicsView(scene);
    27. view->resize(1024, 768);
    28. view->show();
    29.  
    30. timer->start();
    31. return a.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 12th July 2008 at 09:32. Reason: missing [code] tags

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Removing a QGraphicsPixmapItem from a scene


  3. #3
    Join Date
    Jul 2008
    Posts
    18
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Removing a QGraphicsPixmapItem from a scene

    Ok im going to give that a shot, thanks

Similar Threads

  1. Creating new scene from a part of an old one
    By maverick_pol in forum Qt Programming
    Replies: 6
    Last Post: 28th November 2007, 18:14
  2. How to update scene after removing items
    By nileshsince1980 in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2007, 09:56
  3. Creating a scene from piece of another scene
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2007, 17:51
  4. How to use QGraphicsView and Scene right ...
    By Mike in forum Qt Programming
    Replies: 6
    Last Post: 22nd January 2007, 08:51

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.