Pergunta

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.

Foi útil?

Solução

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

Outras dicas

You can definitely get the view's size. There are two ways to go about it:

  1. Attach an event filter object to your view: myView->installEventFilter(filterObject). The filterObject's eventFilter method will be invoked for all events reaching your view, including resize events.

  2. Use a custom view class and reimplement resizeEvent. This method gets called each time the widget is resized. Do note that designer allows you to add custom classes without having to write plugins.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top