Hi everyone,

I'm new to the forum, and pretty much new to Qt. I would like some tips on how I can create the widget layout I'm looking for.

Intention
I have a widget, DisplayArea, which is pretty much only a frame. I want it to have a fixed width, but want to be able to re-size it vertically. Inside this area I want to add one or many widgets which are of the same width as the DisplayArea, but may be of any height. The widgets may also change size during runtime (clicking hide/show on information, etc). I want the DisplayArea to at all times be of just enough size to contain these sub-widgets.

For example, DisplayArea with one sub-widget, displaying a name
Qt Code:
  1. ________________
  2. |Name: Bobruisk|
  3. ^^^^^^^^^^^^^^
To copy to clipboard, switch view to plain text mode 

Now I may add another widget containing a button to the display area:
Qt Code:
  1. ________________
  2. |Name: Bobruisk|
  3. | <BUTTON> |
  4. ^^^^^^^^^^^^^^
To copy to clipboard, switch view to plain text mode 

When this button is clicked, I want it to expand the sub-widget, and the DisplayArea, so that some hidden information is shown;
Qt Code:
  1. ________________
  2. |Name: Bobruisk|
  3. | <BUTTON> |
  4. | Address: |
  5. | Bobroad 2 |
  6. | 123 53 |
  7. | Bobruisk |
  8. | Ukraine |
  9. ^^^^^^^^^^^^^^
To copy to clipboard, switch view to plain text mode 

If the button is clicked again, the adress information should hide again, and the widgets be re-sized to what they were before.

What I have done so far
All done in Qt Designer:
I have created a DisplayAreaWidget which is is a QFrame. I have changed all the margins in the default layout to 0 so that the sub-widgest should stack tightly.

I have created the Name-widget (First line placed inside the DisplayArea). It is a QWidget containing a single QLineEdit.

I have created the Adress-widget (With the button that shows/hides adress). It is a QWidget containing a QPushButton (togglable) and a QLineEdit (Placeholder). I have connected the toggled signal to the show slot of the QLineEdit. The showing/hiding works just fine.

Problems
I have a couple of problems that I am unable to resolve.

First, when I create the Name and Adress widgets with the DisplayArea as parent, they do not get a nice layout. The AdressWidget goes pretty much on top of the NameWidget. I create them using the DisplayArea as parent in the QWidget constructor.

Second, the AdressWidget does not automatically re-size when information is hidden/shown. When the data is hidden, the button is large. When data is shown, the button is smaller. It seems the widget itself is of constant size, but the components (QPushButton /QLineEdit) are re-sized instead.

So;

how can I make the sub-widgets (Name/Adress/...) arrange nicely under eachother?
how can I make the widgets re-size so that they are just large enough to hold their contents?

I hope I've managed to make my question clear. I'll clarify, if needed

Thanks for any assistance!

//Bobruisk