Results 1 to 5 of 5

Thread: Proper Setup for Using the Graphics View Framework

  1. #1
    Join Date
    Jun 2006
    Location
    Colorado
    Posts
    12
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Proper Setup for Using the Graphics View Framework

    I would like to create a 2D Plotter that allows a user to plot various items (Position, lines, etc) on a map of the world. I'm concerned about the organization of where to put the attributes a features of this application.

    I need to give the user the ability to control the zoom (in/out) of the scene, Capturing a image of the plot and saving it to either a file or printing it. The user must be also able to interact with the plot via the mouse.

    Should I put the zoom functionality into the reimplemented QGraphicsView or instead the QGraphicsScene. The same for printing/saving the plot.

    I have a feeling that I need to handle the mouse interaction in my object that reimplements the QGraphicScene but handling the mouse events do I need to use QGraphicsSceneMouseEvent instead of QMouseEvent?

    I'm using the Qt 4.6.1 Version (Its great btw) but I've also noticed that the class QMatrix is now listed as being obsolete with the recommendation not to use it. But there are functions throughout the Graphics View Framework that seem to rely on it.

    Thank you for your time
    Last edited by Wazman; 26th January 2010 at 18:58.

  2. #2
    Join Date
    Jun 2006
    Location
    Colorado
    Posts
    12
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Proper Setup for Using the Graphics View Framework

    I've done some more research and it appears that I should do the zoom (in/out) in the class reimplented from QGraphicsView and Printing is best implemented from QGraphicsView. But I'm still concerned about making new code that relys on using QMatrix class is there recommended replacement.
    Last edited by Wazman; 26th January 2010 at 18:59.

  3. #3
    Join Date
    Jun 2006
    Location
    Colorado
    Posts
    12
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Proper Setup for Using the Graphics View Framework

    Please any help would be appreciated.

  4. #4
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Proper Setup for Using the Graphics View Framework

    i have similar situation, i delegate the funtions as follow.

    thing to do in the QGraphicsScene
    - Save / load plot
    - create the plot

    things to do in the QGraphicsView
    - zooming and affine tranformations
    - management of items selection
    - printing plot.

    printing can be done in the scene or the view. only try to be consistent in the assigment.
    try not print all plot in the scene and print current selection in views.

    QMatrixis obsolete, QTransform is the recommended class to tranformation. QGraphicsView have function has QMatrix based function, but is prefered using the QTransform version. intead of matrix() use transform().
    Last edited by ecanela; 27th January 2010 at 03:16. Reason: updated contents

  5. The following user says thank you to ecanela for this useful post:

    Wazman (27th January 2010)

  6. #5
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Proper Setup for Using the Graphics View Framework

    The way I'd think about how to organize your functions, is to think about what difference between the QGraphicsScene and the QGraphicsView. The QGraphicsScene contains the actual canvas that you are drawing. In your case it would be the map of the world and the other graphical items. The QGraphicsView is like the window into your scene, so with this thinking Zooming and Panning would be handled in the View.

    As for printing/saving, as ecanela said, they can be handled in either the scene or the view. However, if you handle it in the view remember that unless you add special code, it will only print/save what is currently being viewed in the View. If you handle printing/saving in the scene, then the entire scene will be printed/saved.

    For mouse interactions, you can override the mouseMoveEvent, mousePressEvent and mouseReleaseEvent in either the QGraphicsView or QGraphicsScene. Depending on what you're doing it might be easier and better organized if you can handle it in the widgets/items that you are drawing.

    Lastly, if you are just doing simple zoom in/out, try using QGraphicsView::scale. This way, you won't need to worry about playing with the transformation matrix.

    Good Luck!

  7. The following 2 users say thank you to dchow for this useful post:

    mlik (14th May 2010), Wazman (28th January 2010)

Similar Threads

  1. Problem about Graphics View Framework
    By FinderCheng in forum Qt Programming
    Replies: 5
    Last Post: 3rd November 2009, 08:16
  2. Problem with Graphics View Framework
    By Disperato in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2009, 20:44
  3. Issues with the Graphics View Framework
    By lni in forum Qt Programming
    Replies: 8
    Last Post: 26th April 2009, 14:13
  4. about the contextMenuEvent in graphics view framework
    By bingoking in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2009, 06:04
  5. Replies: 4
    Last Post: 5th August 2008, 19:55

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.