I've developed a custom widget that draws some data giving a set of data points. I am placing the custom widget in a dialog that uses a layout manager. I'd like to put spacers on either side to keep the widget in the center of the dialog; however, that results in my custom widget being shrunk to nothing - namely because I do not have sizeHint() setup.

My problem comes in that I would like the sizeHint() to be relative to the object being drawn and the dialog area. The data for my coordinates comes in inches or millimeters. I am successfully using a QPainter with a matrix transform to scale it to the area available, so it draws nicely and I can scale it, and even discovered how to use QSize in the resizeEvent() to keep the aspect ratio correct. (I really wish they'd put that trick for aspect ratios in the documentation. It would be so much more helpful and easier to find that way.)

However, I am perplexed at how to determine an appropriate size for the sizeHints (sizeHint, minimumSize, etc) without resorting to generating an aspect ratio corrected statically sized QSize object - e.g. setting up a QSize with a specific, hard-coded box size (i.e. 30x40) and then using the QSize::scale(QSize(w,h),Qt::KeepAspectRatio) functionality to maintain the correct aspect ratio.

I don't want to make the software use up too much screen real estate, or make the widgets too small.

What is the correct way to do this?

TIA,

Ben