You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, May 10th 2013, 9:36am

QGraphicsView view on fixed area

Hello,

I have a simple status display, I implemented as a QGraphicsScene. Now I want to show this display in a QGraphicsView.

I want to:
  • keep the aspect ratio of the scene
  • view all the items of the status display at once
  • want the display to be as large as possible (= zoom into the scene as far as possible without any items leaving the view)
  • always keep these constraints (even on resize events and such).
I do not want:
  • manual zooming by the user.
  • scrollbars
I thought this task should be simple. Like: ok there is this rect (a,b,w,h) and this should be shown entirely but as large as possible. However I didn't find a simple way to do so. Or no reliable way, at all. I tried fitInView (called once after setting up the scene and adding it to the view and after each resize event), but while it ensures that all items are visible, it doesn't ensure they are as large as possible. Or even reasonable large. I had occasions where my display populated less than 10% of the QGraphicsView. So I tried to zoom into the scene with a large factor and then call fitInView. This works in most cases, but sometimes, for some strange reason, some items are not displayed. Additionally it is kind of an awful hack.
Any ideas or comments?

Thanks

DrFaust