8

I'm using qt designer only for ui layout

This is almost the same question as this one : QVBoxLayout: How to vertically align widgets to the top instead of the center

but i'm interested on how to do that in qt designer. I don't see any option in QVBoxLayout for that top alignment.

enter image description here

Community
  • 1
  • 1
bysreg
  • 793
  • 1
  • 9
  • 30

2 Answers2

11

Right-click the relevant widget and select Layout alignment > Top.

(NB: the new alignment will only be shown in preview mode).

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Thanks for the answer. to add to the answer, to preview it without starting application (you just want to preview that one .ui file) you can click on Tools>Form Editor>Preview... – bysreg Mar 12 '17 at 03:15
  • What if the thing you want to top-align is another layout, inside the outer layout? I.e., I have a vertical layout, inside it is a grid layout, and I want the grid layout to be top-aligned inside the vertical layout? Or alternatively, if you want to get rid of the vertical layout since it has only one thing inside it: I have a horizontal layout containing several things, one of which is a grid layout; how can I top-align the grid layout within the horizontal layout? – bhaller Jul 27 '19 at 23:18
  • 1
    @bhaller Put the grid inside a container widget. – ekhumoro Jul 27 '19 at 23:28
  • @ekhumoro, it took me some head-scratching but I got there. :-> I made a QFrame container widget, using a grid top-level-layout, and put the contents of the old grid layout into that; so the grid layout itself ceased to exist. That is working well. Thanks. – bhaller Jul 28 '19 at 15:59
0

I had the same problem, but solved it a different way, it even shows up on-screen:

Add whatever controls you want to the QVBoxLayout, then at the end add a Spacer (verticalSpacer), this pushes everything to the top, or you can add the verticalSpacer first to push everything down.

Scott Hather
  • 443
  • 5
  • 15