pub struct Layout<'a> { /* private fields */ }
Expand description
Notice these docs are heavy WIP and not very relevent yet
This is an abstract base class inherited by the concrete classes QBoxLayout, QGridLayout, QFormLayout, and QStackedLayout.
For users of QLayout subclasses or of QMainWindow there is seldom any need to use the basic functions provided by QLayout, such as setSizeConstraint() or setMenuBar(). See Layout Management for more information.
To make your own layout manager, implement the functions addItem(), sizeHint(), setGeometry(), itemAt() and takeAt(). You should also implement minimumSize() to ensure your layout isn’t resized to zero size if there is too little space. To support children whose heights depend on their widths, implement hasHeightForWidth() and heightForWidth(). See the Border Layout and Flow Layout examples for more information about implementing custom layout managers.
Geometry management stops when the layout manager is deleted.
See also: LayoutItem
{Layout Management}
{Basic Layouts Example}
{Border Layout Example}
{Flow Layout Example}
Licence
The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Implementations
sourceimpl<'a> Layout<'a>
impl<'a> Layout<'a>
sourcepub fn margin(&self) -> i32
pub fn margin(&self) -> i32
Use setContentsMargins() and getContentsMargins() instead.
See also: [contents_rect()
]
spacing
sourcepub fn spacing(&self) -> i32
pub fn spacing(&self) -> i32
If no value is explicitly set, the layout’s spacing is inherited from the parent layout, or from the style settings for the parent widget.
For QGridLayout and QFormLayout, it is possible to set different horizontal and vertical spacings using setHorizontalSpacing()
and setVerticalSpacing() . In that case, spacing() returns -1.
See also: [contents_rect()
]
[get_contents_margins()
]
[Style::layout_spacing
]
[Style::pixel_metric
]
sourcepub fn set_margin(&self, arg0: i32) -> &Self
pub fn set_margin(&self, arg0: i32) -> &Self
pub fn set_spacing(&self, arg0: i32) -> &Self
sourcepub fn set_contents_margins(
&self,
left: i32,
top: i32,
right: i32,
bottom: i32
) -> &Self
pub fn set_contents_margins(
&self,
left: i32,
top: i32,
right: i32,
bottom: i32
) -> &Self
Sets the left, top, right, and bottom margins to use around the layout.
By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
See also: [get_contents_margins()
]
[Style::pixel_metric
]
{QStyle::}{PM_LayoutLeftMargin}
{QStyle::}{PM_LayoutTopMargin}
{QStyle::}{PM_LayoutRightMargin}
{QStyle::}{PM_LayoutBottomMargin}
Sets the margins to use around the layout.
By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
See also: [contents_margins()
]
sourcepub fn set_contents_margins_2<M: MarginsTrait<'a>>(&self, margins: &M) -> &Self
pub fn set_contents_margins_2<M: MarginsTrait<'a>>(&self, margins: &M) -> &Self
Sets the left, top, right, and bottom margins to use around the layout.
By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
See also: [get_contents_margins()
]
[Style::pixel_metric
]
{QStyle::}{PM_LayoutLeftMargin}
{QStyle::}{PM_LayoutTopMargin}
{QStyle::}{PM_LayoutRightMargin}
{QStyle::}{PM_LayoutBottomMargin}
Sets the margins to use around the layout.
By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
See also: [contents_margins()
]
sourcepub fn contents_margins(&self) -> Margins<'_>
pub fn contents_margins(&self) -> Margins<'_>
Extracts the left, top, right, and bottom margins used around the layout, and assigns them to * left, * top, * right, and * bottom (unless they are null pointers).
By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
See also: [set_contents_margins()
]
[Style::pixel_metric
]
{QStyle::}{PM_LayoutLeftMargin}
{QStyle::}{PM_LayoutTopMargin}
{QStyle::}{PM_LayoutRightMargin}
{QStyle::}{PM_LayoutBottomMargin}
sourcepub fn contents_rect(&self) -> Rect<'_>
pub fn contents_rect(&self) -> Rect<'_>
Returns the layout’s geometry() rectangle, but taking into account the contents margins.
See also: [set_contents_margins()
]
[get_contents_margins()
]
sourcepub fn set_alignment<W: WidgetTrait<'a>>(
&self,
w: &W,
alignment: Alignment
) -> bool
pub fn set_alignment<W: WidgetTrait<'a>>(
&self,
w: &W,
alignment: Alignment
) -> bool
Sets the alignment for widget w to alignment and returns
true if w is found in this layout (not including child
layouts); otherwise returns false.
Overloads
Sets the alignment for the layout l to alignment and
returns true
if l is found in this layout (not including child
layouts); otherwise returns false.
sourcepub fn set_alignment_2<L: LayoutTrait<'a>>(
&self,
l: &L,
alignment: Alignment
) -> bool
pub fn set_alignment_2<L: LayoutTrait<'a>>(
&self,
l: &L,
alignment: Alignment
) -> bool
Sets the alignment for widget w to alignment and returns
true if w is found in this layout (not including child
layouts); otherwise returns false.
Overloads
Sets the alignment for the layout l to alignment and
returns true
if l is found in this layout (not including child
layouts); otherwise returns false.
Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins(). All child widgets are placed below the bottom edge of the menu bar.
Returns the menu bar set for this layout, or 0 if no menu bar is set.
sourcepub fn parent_widget(&self) -> Option<Widget<'_>>
pub fn parent_widget(&self) -> Option<Widget<'_>>
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget.
If the layout is a sub-layout, this function returns the parent widget of the parent layout.
See also: [parent()
]
sourcepub fn invalidate(&self) -> &Self
pub fn invalidate(&self) -> &Self
sourcepub fn activate(&self) -> bool
pub fn activate(&self) -> bool
Redoes the layout for parentWidget() if necessary.
You should generally not need to call this because it is automatically called at the most appropriate times. It returns true if the layout was redone.
See also: [update()
]
[Widget::update_geometry
]
sourcepub fn update(&self) -> &Self
pub fn update(&self) -> &Self
Updates the layout for parentWidget().
You should generally not need to call this because it is automatically called at the most appropriate times.
See also: [activate()
]
[invalidate()
]
sourcepub fn add_widget<W: WidgetTrait<'a>>(&self, w: &W) -> &Self
pub fn add_widget<W: WidgetTrait<'a>>(&self, w: &W) -> &Self
Adds widget w to this layout in a manner specific to the layout. This function uses addItem().
sourcepub fn add_item<L: LayoutItemTrait<'a>>(&self, arg0: &L) -> &Self
pub fn add_item<L: LayoutItemTrait<'a>>(&self, arg0: &L) -> &Self
Implemented in subclasses to add an item. How it is added is specific to each subclass.
This function is not usually called in application code. To add a widget to a layout, use the addWidget() function; to add a child layout, use the addLayout() function provided by the relevant QLayout subclass.
Note: The ownership of item is transferred to the layout, and it’s the layout’s responsibility to delete it.
See also: [add_widget()
]
[BoxLayout::add_layout
]
[GridLayout::add_layout
]
sourcepub fn remove_widget<W: WidgetTrait<'a>>(&self, w: &W) -> &Self
pub fn remove_widget<W: WidgetTrait<'a>>(&self, w: &W) -> &Self
Removes the widget widget from the layout. After this call, it is the caller’s responsibility to give the widget a reasonable geometry or to put the widget back into a layout or to explicitly hide it if necessary.
Note: The ownership of widget remains the same as when it was added.
See also: [remove_item()
]
[Widget::set_geometry
]
[add_widget()
]
sourcepub fn remove_item<L: LayoutItemTrait<'a>>(&self, arg0: &L) -> &Self
pub fn remove_item<L: LayoutItemTrait<'a>>(&self, arg0: &L) -> &Self
Removes the layout item item from the layout. It is the caller’s responsibility to delete the item.
Notice that item can be a layout (since QLayout inherits QLayoutItem).
See also: [remove_widget()
]
[add_item()
]
sourcepub fn expanding_directions(&self) -> Orientations
pub fn expanding_directions(&self) -> Orientations
Returns whether this layout can make use of more space than sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only one dimension, whereas Qt::Vertical | Qt::Horizontal means that it wants to grow in both dimensions.
The default implementation returns Qt::Horizontal | Qt::Vertical. Subclasses reimplement it to return a meaningful value based on their child widgets’s size policies
See also: [size_hint()
]
sourcepub fn minimum_size(&self) -> Size<'_>
pub fn minimum_size(&self) -> Size<'_>
Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications.
The returned value doesn’t include the space required by QWidget::setContentsMargins() or menuBar().
The default implementation allows unlimited resizing.
sourcepub fn maximum_size(&self) -> Size<'_>
pub fn maximum_size(&self) -> Size<'_>
Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications.
The returned value doesn’t include the space required by QWidget::setContentsMargins() or menuBar().
The default implementation allows unlimited resizing.
sourcepub fn item_at(&self, index: i32) -> Option<LayoutItem<'_>>
pub fn item_at(&self, index: i32) -> Option<LayoutItem<'_>>
Must be implemented in subclasses to return the layout item at index. If there is no such item, the function must return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.
This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.
See also: [count()
]
[take_at()
]
sourcepub fn take_at(&self, index: i32) -> Option<LayoutItem<'_>>
pub fn take_at(&self, index: i32) -> Option<LayoutItem<'_>>
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is removed, other items will be renumbered.
The following code fragment shows a safe way to remove all items from a layout:
See also: [item_at()
]
[count()
]
sourcepub fn index_of<W: WidgetTrait<'a>>(&self, arg0: &W) -> i32
pub fn index_of<W: WidgetTrait<'a>>(&self, arg0: &W) -> i32
Searches for widget widget in this layout (not including child layouts).
Returns the index of widget, or -1 if widget is not found.
The default implementation iterates over all items using itemAt()
sourcepub fn count(&self) -> i32
pub fn count(&self) -> i32
Must be implemented in subclasses to return the number of items in the layout.
See also: [item_at()
]
sourcepub fn replace_widget<W: WidgetTrait<'a>>(
&self,
from: &W,
to: &W,
options: FindChildOptions
) -> Option<LayoutItem<'_>>
pub fn replace_widget<W: WidgetTrait<'a>>(
&self,
from: &W,
to: &W,
options: FindChildOptions
) -> Option<LayoutItem<'_>>
Searches for widget from and replaces it with widget to if found.
Returns the layout item that contains the widget from on success.
Otherwise 0
is returned. If options contains Qt::FindChildrenRecursively
(the default), sub-layouts are searched for doing the replacement.
Any other flag in options is ignored.
Notice that the returned item therefore might not belong to this layout, but to a sub-layout.
The returned layout item is no longer owned by the layout and should be either deleted or inserted to another layout. The widget from is no longer managed by the layout and may need to be deleted or hidden. The parent of widget from is left unchanged.
This function works for the built-in Qt layouts, but might not work for custom layouts.
See also: [index_of()
]
pub fn total_height_for_width(&self, w: i32) -> i32
pub fn total_minimum_size(&self) -> Size<'_>
pub fn total_maximum_size(&self) -> Size<'_>
pub fn total_size_hint(&self) -> Size<'_>
sourcepub fn set_enabled(&self, arg0: bool) -> &Self
pub fn set_enabled(&self, arg0: bool) -> &Self
Enables this layout if enable is true, otherwise disables it.
An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.
By default all layouts are enabled.
See also: [is_enabled()
]
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true
if the layout is enabled; otherwise returns false.
See also: [set_enabled()
]