2

I have created a QWidget with lots of children widgets in it. In order to look at the whole picture I want to scale the QWidget down. Then scale it back. However the QWidget doesn't have a scale interface.

The QGraphicsView has a scale interface so I tried to put the QWidget in a QGraphicsView. The scale works, however it's very cumbersome to do drag&drop in a QGraphicsView(There is a question on stackoverflow about this).

So are there any way else to scale a QWidget?

Community
  • 1
  • 1
kkpattern
  • 948
  • 2
  • 7
  • 31
  • Is there a reason why you cannot use the layouts mechanism to scale the widgets and simply set the size for the mainWindow? Or do you need to change the content scale as well? – Mailerdaimon Jun 30 '15 at 12:39
  • @Mailerdaimon I need to change the content scale as well. Also because I need to place the child widgets in absolute positions, so I didn't use a layout. – kkpattern Jun 30 '15 at 12:51
  • you could use [qApp::allWidgets](http://doc.qt.io/qt-4.8/qapplication.html#allWidgets) and resize all Widgets. You would then need to adjust content sizes by hand which is cumbersome as well. – Mailerdaimon Jun 30 '15 at 13:23
  • Have you tried to set `sizePolicy` as fixed and then call `setGeometry` with whatever you need, in a function hat gets a scale argument ? (If I understand your question correctly, your fight is with absolute positions of objects which is hard to do when using layouts) – Thalia Jun 30 '15 at 15:31
  • @Thalia Thank you. I tried `sizePolicy` and `setGeometry`, it's not what I want. When I scale the `QWidget` I need the child widgets also scale. Like zoom a picture. – kkpattern Jun 30 '15 at 15:45

1 Answers1

0

There is no explicit support for such functionality in Qt. The solutions, one of which you've found, are:

  1. Embed the parent QWidget in a QGraphicsWidget, then view it on a scene. Drag and drop are addressed here.

  2. Manually render() the widget in a view widget's paintEvent. You'll have to forward all events to the rendered widget, after applying scaling to any coordinates, and while maintaining requisite invariants. The view widget will have to act, to the outside, as if it was the viewed widget, other than the change of scale. This will take care of drag&drop.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313