Search code examples
qtqgraphicsviewqgraphicsscene

How to get the size of QGraphicsView that is in a layout?


I'm new to Qt programming and I am developing a drawing application. I have a class MyWidget which has a member QGraphicsView. MyWidget is a member of another class MainWidget (which has other widgets as well and all of them are in a layout).MainWidget is the central widget of my subclass of QMainWindow.

I have created functions to scale the view with the mouse wheel event and a function to drag the scene around.

The problem is - I want to set the Scene's size to be fixed, and to be 3 times the size of the view, but since the view is managed by a layout in order to take as much space as possible I can't get the view's size?

Any help appreciated.


Solution

  • the size property will give you the current size of your widget:

    http://qt-project.org/doc/qt-4.8/qwidget.html#size-prop

    Alternatively, you could subclass QGraphicsView and re-implement the resizeEvent:

    http://qt-project.org/doc/qt-4.8/qwidget.html#resizeEvent

    For a full example, have a look into:

    http://qt-project.org/doc/qt-4.8/widgets-scribble.html