Results 1 to 4 of 4

Thread: Multiple QGraphicsViews with one QGraphicsScene

  1. #1
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Multiple QGraphicsViews with one QGraphicsScene

    Hi,

    I am trying to display the items on a graphics scene on two distinct graphics views. My problem is that, I don't want to show all the items on the graphics scene in both views. For example, in my application, on view 1, I will start an editor for the user to draw some items on one view and when the user finishes editing, view 2 will display the newly added item.

    Is it possible with one graphics scene?

    Sami

  2. #2
    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: Multiple QGraphicsViews with one QGraphicsScene

    View displays what a scene has. A scene may have multiple views,,, like in 40000 chip demo in Qt Demos..
    You can have a editor scene, or even may be a widget. Then from that widget create a QGraphicsItem and add it to mainScene.

  3. #3
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple QGraphicsViews with one QGraphicsScene

    Quote Originally Posted by aamer4yu View Post
    View displays what a scene has. A scene may have multiple views,,, like in 40000 chip demo in Qt Demos..
    You can have a editor scene, or even may be a widget. Then from that widget create a QGraphicsItem and add it to mainScene.
    But I need to display all the items that are not edited. So if I use an editor scene, I need to add copies of all the items of main scene to the editor scene and that would cost very much.

  4. #4
    Join Date
    Mar 2010
    Posts
    55
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multiple QGraphicsViews with one QGraphicsScene

    I would do it this way:

    - Add a flag to your item which indicates if the item should be rendered in view 2
    - Subclass QGraphicsView, and this will be your view 2
    - In your new class, reimplement the paintEvent function yourself. In this function, you iterate through each item to draw. If that item has the flag set, call QGraphicsView::paintEvent and pass it the QPaintEvent argument, otherwise do nothing

    Now when you add an item, by default the flag is set to false, so it doesn't get rendered in view 2. When you finish drawing the item, set it's flag to true, tell view 2 to update, and you're set!

    [edit]
    Ok I found another way, while sifting through the docs looking for something else completely.
    QGraphicsView has a property called ViewportUpdateMode, which controls how this *particular* QGraphicsView updates itself. If you set this property to QGraphicsView::NoViewportUpdate, then according to the docs,

    QGraphicsView will never update its viewport when the scene changes; the user is expected to control all updates. This mode disables all (potentially slow) item visibility testing in QGraphicsView, and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally.
    This sounds like what you need. So when you start drawing an item, set view 2's update mode to NoViewportUpdate, and when your drawing finishes, reset the mode to whatever it was before (MinimalViewportUpdate by default) and send an update signal. I haven't tested this so I have no idea if it will work, but you can try.
    Last edited by JovianGhost; 22nd March 2010 at 03:18.

Similar Threads

  1. QGraphicsScene and multiple selection
    By Bill in forum Newbie
    Replies: 1
    Last Post: 4th August 2009, 15:19
  2. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27
  3. Replies: 3
    Last Post: 2nd February 2009, 23:40
  4. Help on QGraphicsScene
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 14:20
  5. Replies: 0
    Last Post: 21st December 2006, 11:48

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.