19

I made a "widget" in Qt Designer with about a dozen controls organized into horiz. and vert. layouts. Oddly, every horizontal layout wants to be some large size, about 400 px wide, when the whole form is set to be 275px wide. Buttons etc contained within are too wide for the form. When I resize the widget form vertically or horizontally (sometimes with the max width turned off) the various layouts won't resize. Manually setting widths (or min widths, or max widths) may affect the sizes of the controls, but not their spacing within the layout. Spacers inserted to keep some controls at the top and some others at the bottom with a flexible space between, just don't work at all.

What (probably) obvious thing am I overlooking?

(I am normally not an applications or GUI programmer, a total caveman at this.)

DarenW
  • 16,549
  • 7
  • 63
  • 102

1 Answers1

49

Don't blame yourself, I think Qt's Layout logic is a bit confusing when you start to deal with. If I understood well what you are saying, the contents of the form are not "connected", i.e. not resizing and not restricted by the form size, right? I think you have missed to set a "centralWidget layout". Try the following:

  1. Open your form by double clicking it in QtCreator (I don't use the QtDesigner frequently but I think the editor layout is almost the same on both tools).

  2. Go to the top-right window (the one having 2 columns "Object-Class") and Right-Click with your mouse at the root object (e.g. MainWindow).

  3. A context menu will appear. Click on "Lay out" (last menu item) and select "Layout Vertically" or "Layout Horizontally"

enter image description here

These actions will create a layout on the centralWidget object. If you select the "centralWidget" in the "Object-Class" window you can then view & change the layout properties in the (bottom-right) Property-Value window; they are the last properties in list.

More important, after you add a layout in your centralWidget, the contents of your form should be resizing along & limited by your form's size.

I hope this helps.

0x8BADF00D
  • 7,138
  • 2
  • 41
  • 34
Fivos Vilanakis
  • 1,490
  • 12
  • 13
  • Hi Fivos, I followed your steps and after changing layout, all my layout changed to be totally different from what I have. Currently I have plot area on the left and GUI buttons like dropdown, click-on etc on the right panel. After changing to either horizontal and vertical layout, these original layout become totally mess. could you please give me a hand? I have been looking for solutions for a long time and today I finally so glad to find your post. – roudan Dec 22 '21 at 20:02
  • 1
    Hi @roudan, as you can see the question is about 10+ years old, the Qt was v4.7, now isv6.x and it's really difficult to guess your specific design and give you a useful advice. (a) Try to use "Lay Out in a Grid" or "Lay Out in a Form Layout" (b) Ensure that you have a central widget in your form which contains all your other widgets and (c) if everything other fails, try to find any Qt example which has a similar top structure as your app and study the layout settings and structure of the main window. – Fivos Vilanakis Dec 23 '21 at 04:47