PDA

View Full Version : Resize with QSizeGrip



mhoover
30th November 2009, 20:06
Right now I'm displaying pixmaps at the central widget in a QMainWindow.

The problem is the pixmap does not auto-scale to smaller than the original size automatically, although I can scale it smaller using QPixmap::scaleTo().

The problem with using scaleTo() is I want to call it when the user is resizing the QMainWindow, but QMainWindow does not generate a resizeEvent() if the user is trying to make the window smaller than what the child widgets can hold. Since my QLabel that displays the pixmaps is always expanding, any shrinking of the window will be seen as too small for the child widgets and the resizeEvent function never gets called.

So I'm trying to figure out how I can catch the code when the user clicks on the sizeGrip so I can properly set the parameters in scaleTo().

I suppose I could subclass a QSizeGrip, re-implement the mouseClickEvent, and then disable the default QSizeGrip I get for free using the QMainWindow class.

Would that work? Is there a more elegant way to do it?

mhoover
30th November 2009, 20:41
Hmm ... reimplementing QSizeGrip sounds like a bumpy road at best.

I checked out this example:

http://doc.trolltech.com/4.2/desktop-screenshot.html

And it looks like something very similar to what I'm doing (reimplementing a QLabel to display pixmaps and trying to resize it). Unfortunately their strategy was to call resizeEvent in the QLabel subclass. This resizeEvent is never triggered if the QLabel already takes up all the discretionary space and the user is trying to make the window smaller.

So it doesn't help.