Im creating a new QWidget in Qt Designer, with a frame which contains a QLabel and a QTextEdit. I can set the geometry of all these elements, and set them to be fixed so that their height/width never change:
In this example, my QLabel and QLineEdit are in the top right-hand corner of their parent frame. If I now set a layout to the frame (which I need to do to ensure elements remain in their correct place when resizing windows, or if the frame is the main widget of a QScrollArea), then the elements are moved, even within the reference of the frame:
Given I'm trying to create a very precise layout by manually setting the element coords, to have them move a seemingly random amount when applying a layout is hugely frustrating. What should I be doing?! I assume I've misunderstood something, but I don't know what!
You can override the defaults by clicking on the parent widget of the layout, and scrolling down to the bottom of the Property Editor, where you'll see a Layout section with the relevant values (-1 means "use the default").
One thing I didn't make clear was that the layout margins and spacing will go back to their defaults every time you break and reset the layout! This can be very annoying at times, but does make sense, because a new layout is created every time you do this.
Anyway, I think the real source of the problem is actually that you are using a Form Layout, which can be much less flexible than the other layouts. What I think you should do is put the label and line-edit in an Horizontal Layout with a Horizontal Spacer at the end. Then put a Vertical Spacer below the Horizontal Layout, and add a Vertical Layout to the Frame. This arrangement will keep the label and line-edit in the top-left corner of the Frame. With that in place, you can finally set the Vertical Layout margins to zero to get the desired result.
Instead of trying to rigidly control the size and position of everything, use layouts to convey design intent: These two controls belong together, these identical items should be in a column, and so on.
The first time you try Designer, a prompt might appear requesting your permission to provide design ideas for you. To use Designer, select Turn on. If you're not sure the feature is turned on, go to File > Account, and under Account Privacy select Manage Settings. Check the box to Turn on optional connected experiences.
Learn more about the different features in Designer, to elevate your presentations. Easily add a photo to your title slide and get a cohesive design across your slides. You can use SmartArt graphics to turn text into engaging visuals. Designer, looks for key terms that is has illustrations for and displays relevant visuals in various layouts. Find out what other features Designer has to offer.
When you start a blank presentation and add text to the slide, Designer suggests high-quality photos that align with the slide's content. It also recommends a color scheme that goes well with the photo you choose. All the slides in the presentation will fit together visually.
To use Designer, make sure that Office "connected experiences" are turned on. In the ribbon, go to File > Account, and under Account Privacy select Manage Settings. Then go to Turn on optional connected experiences and check the box to turn on. For more information, see Enabling and disabling intelligent services.
Designer is a feature for Microsoft 365 subscribers, but some organizations turn off the feature. If you have a Microsoft 365 subscription but don't see the Designer button, ask your IT department.
A single slide isn't selected. This can be the case when multiple slides are selected in the slide thumbnail pane in Normal view, or when the focus in the thumbnail pane is between two slides. It also is the case when the focus is in the Notes pane or you are in Slide Show view rather than Normal view.
Learn more about the different features in Designer to elevate your presentations. Easily add a photo to your title slide and get a cohesive design across your slides. You can use SmartArt graphics to turn text into engaging visuals. Designer looks for key terms that is has illustrations for and displays relevant visuals in various layouts. Find out what other features Designer has to offer.
A slide might not be selected. This can be the case when multiple slides are selected in the slide thumbnail pane in Normal view, or when the focus in the thumbnail pane is between two slides. It's also the case when the focus is in the Notes pane, or when you are in Slide Show view rather than Normal view.
Designer is available for files stored on OneDrive and SharePoint in Microsoft 365. If you don't see the Designer button, or you don't see certain features described on this page, see Requirements for more details.
Learn more about the different features in Designer to elevate your presentations. You can use SmartArt graphics to turn text into engaging visuals. Designer provides suggestions for your pictures, charts, or tables and with various visuals. Find out what other features Designer has to offer.
Before a form can be used, the objects on the form need to be placed into layouts. This ensures that the objects will be displayed properly when the form is previewed or used in an application. Placing objects in a layout also ensures that they will be resized correctly when the form is resized.
Once widgets have been inserted into a layout, it is not possible to move and resize them individually because the layout itself controls the geometry of each widget within it, taking account of the hints provided by spacers. Spacers can be added to the layout to influence the geometries of the widgets.
Layouts can be nested to form a hierarchy. For example, to achieve a typical dialog layout with a horizontal row of buttons, the dialog elements can be laid out using a vertical box layout with a horizontal box layout containing the buttons at the bottom. For an introduction to the Qt layout system, refer to Layout Management.
The form's top level layout can be set by clearing the selection (click the left mouse button on the form itself) and applying a layout. A top level layout is necessary to ensure that your widgets will resize correctly when its window is resized. To check if you have set a top level layout, preview your widget and attempt to resize the window by dragging the size grip.
Similary, top level layouts are set on container widgets (QGroupBox) or on pages of page-based container widgets (QTabWidget, QToolBox and QStackedWidget), respectively. The container widget needs to be selected for this to succeed.
Top level layouts are not visible as separate objects in the Object Inspector. Their properties appear below the widget properties of the main form, container widget, or page of a container widget in the Property Editor.
Layout objects are created by applying 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.
When a child layout object is selected, its parent layout object can be selected by pressing down the Shift key while clicking on it. This makes it possible to select a specific layout in a hierarchy, which is otherwise difficult due to the small frame.
Objects can be inserted into an existing layout by dragging them from their current positions and dropping them at the required location. A blue cursor is displayed in the layout as an object is dragged over it to indicate where the object will be added.
The simplest way to arrange objects on a form is to place them in a horizontal or vertical layout. Horizontal layouts ensure that the widgets within are aligned horizontally; vertical layouts ensure that they are aligned vertically.
Complex 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. However, for some kinds of form layout, a grid arrangement is much more suitable than a nested arrangement of horizontal and vertical layouts.
The QFormLayout class manages widgets in a two-column form; the left column holds labels and the right column holds field widgets such as line edits, spin boxes, etc. The QFormLayout class adheres to various platform look and feel guidelines and supports wrapping for long rows.
Another common way to manage the layout of objects on a form is to place them in a splitter. These splitters arrange the objects horizontally or vertically in the same way as normal layouts, but also allow the user to adjust the amount of space allocated to each object.
3a8082e126