Results 1 to 4 of 4

Thread: QGraphicsView coordinate system

  1. #1
    Join Date
    Jul 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsView coordinate system

    Hello everybody,

    I am dealing with a simple application using a main window with menu bar and tool bar. After that, I set as main widget a QGraphicsView and inside it a QGraphicsScene. What I do is basically design inside QGraphicsScene and it works. But, my problem is that I don't get the size of the View and Scene.
    1) I do
    scene->setSceneRect(0,0,view->width(), view->height())
    to set the scene as big as the view size, that in my case, because I used the showFullScreen() method in the main window, is 640x480. Doing so, I get the scene in the center of the window and the size is a quarter of the main window. Why the scene is not the full size of the view?

    2) If I set, for example,
    scene->setSceneRect(0,0,view->width()+200, view->height()+200)
    then it is bigger as I would want.

    My question is how can I do to get the scene the size of the View and why the view->width() does not work as parameter above. I would really appreciate any help, thx

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView coordinate system

    where you used
    Qt Code:
    1. scene->setSceneRect(0,0,view->width(), view->height())
    To copy to clipboard, switch view to plain text mode 
    ?

    you should do in resizeEvent
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsView coordinate system

    Can also use QGraphicsView::fitInView() with Qt::KeepAspectRatio in the resize event if you don't want distortion due to changes in the width / height ratio on resizing. That also will center the scene in the view.

    Note that calling setSceneRect() will change *all* views of the scene, not just the one with focus. So if you have the same scene displayed in more than one window, you want the method I described (which changes only the scaling used by the view, not the scene dimensions), otherwise the scene will look fine in one view, but not in any of the others.

  4. #4
    Join Date
    Jul 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsView coordinate system

    Thx a lot guys, I try it out and see if it works.

Similar Threads

  1. QGraphicsView coordinate system
    By roband915 in forum Qt Programming
    Replies: 15
    Last Post: 5th December 2013, 06:58
  2. QGraphicsView coordinate system
    By been_1990 in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2010, 16:21
  3. coordinate system
    By Wojtek.wk in forum Newbie
    Replies: 7
    Last Post: 12th April 2010, 13:47
  4. Replies: 1
    Last Post: 9th April 2009, 14:54
  5. The coordinate system
    By avis_phoenix in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2008, 12:16

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.