I'm writing a simulation of an embedded device's screen (which contains custom widgets on top of a main QWidget), and while the native size of the screen is 800x600, I want to be able to scale it up and down by dragging the window's corner. Without diddling with grid layouts and stretchers (which won't scale the fonts up/down), how do I accomplish this sort-of zoom? I think part of the solution might be to create a QTransform and somehow inject that into the QWidget for the entire application, or its QPaintDevice or QPaintEngine. I'd like to do this without putting QTransform in each custom widget, just the "main window" QWidget.
+3
A:
This is possible if you are using QGraphicsView as your main display widget. QGraphicsScene now supports widgets as content, so you can literally just scale them.
I believe the alternative is to reimplement the paint() for each widget, and manually set the transform/scale before the painting of child widgets.
Kaleb Pederson
2009-09-30 16:20:03
This turns out to work nicely--thanks! Here's more detail on what I did: First, follow the instructions for showing a QGraphicsScene in a QGraphicsView. To get the zooming effect, Derive from QGraphicsView and override resizeEvent(), calling 'fitInView( items()[0] );'. Works like a champ! (don't have enough rep yet to vote you up--sorry).
Scott
2009-09-30 17:47:02
You could mark his answer as correct though.
2009-10-01 12:59:31