Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to divide QGridLayout into rows and columns at Design Time in QT?

Tags:

qt

how to divide QGridLayout into rows and columns at Design Time in QT ?

I want to design one form where i want to have 2 columns and 7 rows . I am designing using QTCreator but i am not getting any option of giving rows/columns.

It shows only these properties

enter image description here

like image 284
Bokambo Avatar asked Jun 15 '11 07:06

Bokambo


People also ask

What is grid layout in Qt Designer?

The Grid LayoutComplex form layouts can be created by placing objects in a grid layout. This kind of layout gives the form designer much more freedom to arrange widgets on the form, but can result in a much less flexible layout.

How do I resize a layout in Qt?

Once you have add your layout with at least one widget in it, select your window and click the "Update" button of QtDesigner. The interface will be resized at the most optimized size and your layout will fit the whole window. Then when resizing the window, the layout will be resized in the same way.

How are widgets added to a grid layout?

The normal way to add a layout is by calling addLayout() on the parent layout. Once you have added your layout you can start putting widgets and other layouts into the cells of your grid layout using addWidget(), addItem(), and addLayout().


3 Answers

See Using Layouts in Qt Designer. For you the most important paragraph is this:

The simplest way to manage objects is to apply a layout to a group of existing objects. This is achieved by selecting the objects that you need to manage and applying one of the standard layouts using the main toolbar, the Form menu, or the form's context menu.

  1. place your widgets on the form
  2. arrange them into 2 columns and 7 rows
  3. select all of them
  4. right click on the selected widgets
  5. select Lay Out in a Grid on the context menu.
like image 182
Bill Avatar answered Oct 19 '22 18:10

Bill


QLayout structure is created dynamically as you add widgets to it, there's no way to predefine how many rows/cols a layout have. Maybe you are using the wrong approach to achieve your goal.

like image 35
Riccardo Pedrielli Avatar answered Oct 19 '22 19:10

Riccardo Pedrielli


You can often drag a new UI element to a position between two existing columns to create a new column - the GUI indicates that it's ready to create a new column by showing a blue vertical line to the user (same thing for creation of a new row with a horizontal blue line).

If instead it is showing a red line or outline, that's indicating that it will fit the element currently being dragged into the existing row/column grid at the indicated position, without creating a new row or column.

It can sometimes be quite difficult to get the GUI to play nice - I've have a number of occasions where I can follow this process to create a new column - but not if I try to place the UI element on the row I actually want it on - so instead I end up dropping it on another row to create the column, dropping another of the same UI element where I actually want it, and deleting the first (superfluous) UI element.

Alternatively, it can quite often be easier to simply right click the element with the layout set, select "break layout" from the layout menu, move things about manually and then go back and select "layout in grid" (or whichever other option) from that layout menu - hoping that it will correctly guess where you want things to go in terms of rows and columns. It's usually pretty good at that.

But yes, it probably would be nice to be able to force create a new column/row in a grid layout (perhaps with some default UI element - a label, maybe - inserted as a placeholder to keep the new row/column open) at a predefined position within the grid for those times when the GUI just does not want to play nice.

like image 1
Blair Avatar answered Oct 19 '22 18:10

Blair