QT - Place the buttons in the lower right corner.

I am trying to put a set of buttons so that they are attached to the bottom right of the screen. My problem is that whenever I resize the screen, the buttons are not tied to the lower right, but remain in its current position.

I placed two Push buttons inside the horizontal layout. Then I placed this layout inside a grid layout that contains horizontal and vertical struts. I changed the Layout property of the grid table layout to SetMaximumSize.

What am I doing wrong so that I can snap my buttons to the lower right?

enter image description here

+6
source share
3 answers

You have almost everything right here, but you are probably losing sight of what is very easy to miss when you first start using Qt Designer.

The layout of your grid is inside your widget with a fixed size and position. He also needs to control the layout. If you look at the object inspector in the upper right corner (which contains your hierarchy), you will probably see a top-level widget with a red icon. This means that there is no layout in it. You have two options to fix this ...

  • Place the existing grid layout in another main layout (for example, a vertical layout). You just right-click on your top-level widget in Object Inspector → Lay Out → [Select the type of main layout].
  • Let your grid be the main layout. To do this, you will need to remove the grid layout and arrange your child elements exactly as you have in this picture. Then follow the previous option by right-clicking on the top-level widgets (or empty background) and select Lay out → Grid. This will cause your widgets to appear in the grid with the best visual reference (which you can then fix if necessary), and your grid will be a top-level layout.
+5
source

This grid layout will make placement of other widgets quite difficult. Try instead:

  • Add (left to right) a horizontal spacer and two buttons.
  • Multiply everything.
  • Select "Lay out Horizontally" (Ctrl-H) from the top toolbar of Qt Designer (or Qt Creator) (not from the widget window on the left!).
  • Add a vertical spacer on top of previous widgets.
  • Select the main window by clicking on it (now none of the added widgets are selected).
  • Select "Lay out Vertically" (Ctrl-L) from the top toolbar.
  • Done.
+1
source

It seems you are doing it right. Just forgot to apply the layout to your central widget, right? The grid layout should be placed in your central widget. A more convenient way is to remove the grid layout widget and place the central widget in the grid ;-)

0
source

Source: https://habr.com/ru/post/911782/


All Articles