Results 1 to 3 of 3

Thread: Updating QGraphicsView

  1. #1
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Updating QGraphicsView

    I am writing my first qt program which heavily relies on QGraphicsScene/View. The first items added to the scene(s) while the program starts up show up as expected, while the items I add as it runs are not shown in the view. However, they show up if I rotate the view 360 degrees.

    Is there a way I can force the view to update without having to do an expensive rotation. I think I have tried all the functions in scene/view that I think should force an update and non do.

    linux, qt 4.2.2
    Qt Code:
    1. QGraphicsPixmapItem *particle = new QGraphicsPixmapItem(particlepng);
    2. particle->setPos(xpos[i],ypos[i]);
    3. //particle->update(0,0,10,10);
    4. holeScene[holeNum]->addItem(particle);
    5. //holeView[holeNum]->rotate(360);
    To copy to clipboard, switch view to plain text mode 

    Hope I've given enough info, Thanks

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Updating QGraphicsView

    Quote Originally Posted by has2k1 View Post
    I am writing my first qt program which heavily relies on QGraphicsScene/View. The first items added to the scene(s) while the program starts up show up as expected, while the items I add as it runs are not shown in the view. However, they show up if I rotate the view 360 degrees.

    Is there a way I can force the view to update without having to do an expensive rotation. I think I have tried all the functions in scene/view that I think should force an update and non do.

    linux, qt 4.2.2
    Qt Code:
    1. QGraphicsPixmapItem *particle = new QGraphicsPixmapItem(particlepng);
    2. particle->setPos(xpos[i],ypos[i]);
    3. //particle->update(0,0,10,10);
    4. holeScene[holeNum]->addItem(particle);
    5. //holeView[holeNum]->rotate(360);
    To copy to clipboard, switch view to plain text mode 

    Hope I've given enough info, Thanks
    Firstly answer to the point:
    You can force update by updating the whole scene or view like
    holeScene[*]->update() and holeView[*]->update()

    But the code confuses me a bit. Looks like you are using number of scenes for your program. Not a problem, but are you sure you need more scenes. Or do the scenes correspond to multiple tabs/windows ??

    Also the docs clearly indicate the scene and hence the view is updated whenever an item is added to scene. Just make sure you get the scene,view and item relations right.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. The following user says thank you to Gopala Krishna for this useful post:

    has2k1 (8th April 2007)

  4. #3
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Updating QGraphicsView

    Thanks Gopala. That works really fast. It just did not occur to me that I would have to look at inherited functions from QWidget for that functionality. I had tried QgraphicsView->updateScene to no luck.

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. Simulating Video on QLabel or QGraphicsView
    By forrestfsu in forum Qt Programming
    Replies: 9
    Last Post: 21st March 2007, 10:39
  3. How to make MDI editor with QGraphicsView support
    By Kuzemko in forum Qt Programming
    Replies: 4
    Last Post: 14th February 2007, 17:31
  4. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  5. Regarding QGraphicsView
    By kiranraj in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2006, 04:59

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.