Hi there!
I have a somewhat complex GUI application on my hands and I don't like how it behaves in terms of sizing of widgets. It is a QMainWindow that has a blank central widget that is managed by a layout. Inside the layout is among small and unimportant things on the side, a large QGraphicsView and the QGraphicsView has a QGraphicsScene, of course. So far, the size of the window that opens up is defined in a very hacky way by setting the scene rect to a certain size in the constructor of the graphics scene. When I remove that line, the window opens up to a seemingly default, way too small size. I am looking for a clean solution that implements the following requirements.
- When the application is launched, the window should open up to a predetermined fixed size of say 1024x768, or even better two thirds of the actual resolution available on the screen. Then, the user can resize the window as he pleases.
- The contents of the graphics scene are often changed entirely with the press of a button when the user cycles through geometric scenes of different sizes. Whenever such a switch occurs, the scene should scale according to the current size of the window, i.e. show the entire scene in the available space and it is up to the user to pan and scale as he pleases afterwards.
Can anyone give me some pointers to the best ways of solving these requirements?
- Where is the best place to define the initial size of the window?
- How do I obtain the screen resolution? (I saw different ways in Google, not sure which way is best)
- Since the contents of the scene sometimes change entirely, I would like to leave the scene rect unset and have Qt handle it automatically. Is that correct?
- I would implement the panning and zooming functions using the scale() and translate() functions of the graphics view. Right? The scrollbars are always off, this is all done with the mouse.
- When a scene change occurs, I would use the fitInView() function with the scene rect to make the entire scene visible, right?
- The graphics scene should know nothing about the size of the window and widgets it is embedded in and should certainly not influence the size of the window in any way. Right?
Bookmarks