I have a QGridLayout something like this:

Qt Code:
  1. QGridLayout gLayout;
  2. gLayout->addWidget(new CustomWidget1,0,0,1,1);
  3. gLayout->addWidget(new CustomWidget2,0,1,1,1);
To copy to clipboard, switch view to plain text mode 

As you can see above, the two widgets are laid side by side in a single grid cell each, e.g. :

CW1 | CW2

CustomWidget1 has a size determined by the data it is displaying, and it determines the overall height of gLayout.

CustomWidget2 is an optional display that can be shown or hidden. Showing it should expand the dialog width, but not change the height. I would like CW2 to have a width that matches it's height (which is in turn determined by CW1 and gLayout), making it a square widget. I can't seem to figure out how to do this cleanly without CW2 knowing what size CW1 is through poorly encapsulated means.

Put another way:

What is the best way to create a widget with a flexible height that always has an actual width that matches its actual height?