Unsolved Qt Layout woes !
-
I am having a really hard time trying to understand Qt layout semantics.
Basically, I used designer to create a signup form derived from QWidget. This has no layout defined at the root level, and everything is positioned absolutely, and it all looks good in the designer and in preview.
The mainwindow has a stacked widget as the central widget and I added a page to it. This page has a vertical layout defined, and I added the signup form to it. The signup form is left aligned and centred if I don't add any alignment options.
IF however, I explicitly set it to right aligned then it disappears from the UI altogether. After doing some experimentation, it looks I cannot right align unless every widget is in an explicit layout.
I know I probably should be using layouts throughout to make things more fluid, but unfortunately it's quite a complex form and I don't want to make it look like the average generic form UI.
My question is, what's wrong with having a widget that's got an explicit size set on it (as my signup form has, it has a resize() call in the UI definitions) in being added to a vertical layout and being right aligned?
-
Hi and welcome to devnet,
Please provide a minimal compilable example that shows that behaviour.
Also what version of Qt are you using ?
On what OS ? -
@arshadm said in Qt Layout woes !:
My question is, what's wrong with having a widget that's got an explicit size set on it (as my signup form has, it has a resize() call in the UI definitions) in being added to a vertical layout and being right aligned?
If you put the form itself inside a layout, then the layout can overrule your
resize()
instructions. It is the layout's job to callresize()
on every widget that it manages.The outer layout will query your form to find out how much visual space it needs. Because your form contains no layout, it will happily tell the outer layout that it needs 0 width and 0 height. Therefore, the "outer" layout calls
resize(0, 0)
on your form.To change this behaviour, set your form's minimum size. Alternatively, you can specify a size policy for your form.