QLayout#
The QLayout
class is the base class of geometry managers. More…
Inherited by: QStackedLayout, QGridLayout, QFormLayout, QBoxLayout, QVBoxLayout, QHBoxLayout
Synopsis#
Properties#
sizeConstraint
- The resize mode of the layoutspacing
- The spacing between widgets inside the layout
Functions#
def
activate
()def
addChildLayout
(l)def
addChildWidget
(w)def
addWidget
(w)def
adoptLayout
(layout)def
alignmentRect
(arg__1)def
contentsMargins
()def
contentsRect
()def
getContentsMargins
()def
isEnabled
()def
menuBar
()def
parentWidget
()def
removeItem
(arg__1)def
removeWidget
(w)def
setAlignment
(w, alignment)def
setAlignment
(l, alignment)def
setContentsMargins
(margins)def
setContentsMargins
(left, top, right, bottom)def
setEnabled
(arg__1)def
setMenuBar
(w)def
setSizeConstraint
(arg__1)def
sizeConstraint
()def
totalHeightForWidth
(w)def
totalMaximumSize
()def
totalMinimumHeightForWidth
(w)def
totalMinimumSize
()def
totalSizeHint
()def
unsetContentsMargins
()def
update
()def
widgetEvent
(arg__1)
Virtual functions#
def
addItem
(arg__1)def
count
()def
indexOf
(arg__1)def
indexOf
(arg__1)def
itemAt
(index)def
replaceWidget
(from, to[, options=Qt.FindChildrenRecursively])def
setSpacing
(arg__1)def
spacing
()def
takeAt
(index)
Static functions#
def
closestAcceptableSize
(w, s)
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
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
QLayoutItem
Layout Management Basic Layouts Example Border Layout Example Flow Layout Example
- class PySide6.QtWidgets.QLayout([parent=None])#
- Parameters:
parent –
PySide6.QtWidgets.QWidget
Constructs a new top-level QLayout
, with parent parent
.
The layout is set directly as the top-level layout for parent
. There can be only one top-level layout for a widget. It is returned by layout()
.
If parent
is None
, then you must insert this layout into another layout, or set it as a widget’s layout using setLayout()
.
See also
Note
Properties can be used directly when from __feature__ import true_property
is used or via accessor functions otherwise.
- property PᅟySide6.QtWidgets.QLayout.contentsMargins: PySide6.QtCore.QMargins#
- Access functions:
setContentsMargins
(margins)
- property PᅟySide6.QtWidgets.QLayout.sizeConstraint: SizeConstraint#
This property holds the resize mode of the layout.
The default mode is SetDefaultConstraint
.
- Access functions:
setSizeConstraint
(arg__1)
- property PᅟySide6.QtWidgets.QLayout.spacing: int#
This property holds the spacing between widgets inside the layout.
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.
- Access functions:
spacing
()setSpacing
(arg__1)
- PySide6.QtWidgets.QLayout.SizeConstraint#
The possible values are:
Constant
Description
QLayout.SetDefaultConstraint
The main widget’s minimum size is set to
minimumSize()
, unless the widget already has a minimum size.QLayout.SetFixedSize
The main widget’s size is set to
sizeHint()
; it cannot be resized at all.QLayout.SetMinimumSize
The main widget’s minimum size is set to
minimumSize()
; it cannot be smaller.QLayout.SetMaximumSize
The main widget’s maximum size is set to
maximumSize()
; it cannot be larger.QLayout.SetMinAndMaxSize
The main widget’s minimum size is set to
minimumSize()
and its maximum size is set tomaximumSize()
.QLayout.SetNoConstraint
The widget is not constrained.
See also
- PySide6.QtWidgets.QLayout.activate()#
- Return type:
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
- PySide6.QtWidgets.QLayout.addChildLayout(l)#
- Parameters:
This function is called from addLayout()
or insertLayout()
functions in subclasses to add layout childLayout
as a sub-layout.
The only scenario in which you need to call it directly is if you implement a custom layout that supports nested layouts.
See also
- PySide6.QtWidgets.QLayout.addChildWidget(w)#
- Parameters:
This function is called from addWidget()
functions in subclasses to add w
as a managed widget of a layout.
If w
is already managed by a layout, this function will produce a warning, and remove w
from that layout. This function must therefore be called before adding w
to the layout’s data structure.
- abstract PySide6.QtWidgets.QLayout.addItem(arg__1)#
- Parameters:
arg__1 –
PySide6.QtWidgets.QLayoutItem
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
- PySide6.QtWidgets.QLayout.addWidget(w)#
- Parameters:
Adds widget w
to this layout in a manner specific to the layout. This function uses addItem()
.
- PySide6.QtWidgets.QLayout.adoptLayout(layout)#
- Parameters:
layout –
PySide6.QtWidgets.QLayout
- Return type:
bool
- PySide6.QtWidgets.QLayout.alignmentRect(arg__1)#
- Parameters:
arg__1 –
PySide6.QtCore.QRect
- Return type:
Returns the rectangle that should be covered when the geometry of this layout is set to r
, provided that this layout supports setAlignment()
.
The result is derived from sizeHint()
and expanding(). It is never larger than r
.
- static PySide6.QtWidgets.QLayout.closestAcceptableSize(w, s)#
- Parameters:
- Return type:
Returns a size that satisfies all size constraints on widget
, including heightForWidth()
and that is as close as possible to size
.
- PySide6.QtWidgets.QLayout.contentsMargins()#
- Return type:
Returns the margins used 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
Getter of property contentsMargins
.
- PySide6.QtWidgets.QLayout.contentsRect()#
- Return type:
Returns the layout’s geometry()
rectangle, but taking into account the contents margins.
See also
- abstract PySide6.QtWidgets.QLayout.count()#
- Return type:
int
Must be implemented in subclasses to return the number of items in the layout.
See also
- PySide6.QtWidgets.QLayout.getContentsMargins()#
- Return type:
PyObject
For each of left
, top
, right
and bottom
that is not None
, stores the size of the margin named in the location the pointer refers to.
By default, QLayout
uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
See also
setContentsMargins()
pixelMetric()
PM_LayoutLeftMargin
PM_LayoutTopMargin
PM_LayoutRightMargin
PM_LayoutBottomMargin
- PySide6.QtWidgets.QLayout.indexOf(arg__1)#
- Parameters:
arg__1 –
PySide6.QtWidgets.QLayoutItem
- Return type:
int
Searches for layout item layoutItem
in this layout (not including child layouts).
Returns the index of layoutItem
, or -1 if layoutItem
is not found.
- PySide6.QtWidgets.QLayout.indexOf(arg__1)
- Parameters:
arg__1 –
PySide6.QtWidgets.QWidget
- Return type:
int
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()
.
- PySide6.QtWidgets.QLayout.isEnabled()#
- Return type:
bool
Returns true
if the layout is enabled; otherwise returns false
.
See also
- abstract PySide6.QtWidgets.QLayout.itemAt(index)#
- Parameters:
index – int
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Must be implemented in subclasses to return the layout item at index
. If there is no such item, the function must return None
. 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.
- Return type:
Returns the menu bar set for this layout, or None
if no menu bar is set.
See also
- PySide6.QtWidgets.QLayout.parentWidget()#
- Return type:
Returns the parent widget of this layout, or None
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()
- PySide6.QtWidgets.QLayout.removeItem(arg__1)#
- Parameters:
arg__1 –
PySide6.QtWidgets.QLayoutItem
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
- PySide6.QtWidgets.QLayout.removeWidget(w)#
- Parameters:
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
- PySide6.QtWidgets.QLayout.replaceWidget(from, to[, options=Qt.FindChildrenRecursively])#
- Parameters:
from –
PySide6.QtWidgets.QWidget
options –
FindChildOptions
- Return type:
Searches for widget from
and replaces it with widget to
if found. Returns the layout item that contains the widget from
on success. Otherwise None
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
- PySide6.QtWidgets.QLayout.setAlignment(w, alignment)#
- Parameters:
alignment –
Alignment
- Return type:
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
.
- PySide6.QtWidgets.QLayout.setAlignment(l, alignment)
- Parameters:
alignment –
Alignment
- Return type:
bool
This is an overloaded function.
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
.
- PySide6.QtWidgets.QLayout.setContentsMargins(margins)#
- Parameters:
margins –
PySide6.QtCore.QMargins
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
Setter of property contentsMargins
.
- PySide6.QtWidgets.QLayout.setContentsMargins(left, top, right, bottom)
- Parameters:
left – int
top – int
right – int
bottom – int
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
contentsMargins()
getContentsMargins()
pixelMetric()
PM_LayoutLeftMargin
PM_LayoutTopMargin
PM_LayoutRightMargin
PM_LayoutBottomMargin
- PySide6.QtWidgets.QLayout.setEnabled(arg__1)#
- Parameters:
arg__1 – bool
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
- PySide6.QtWidgets.QLayout.setMenuBar(w)#
- Parameters:
Tells the geometry manager to place the menu bar widget
at the top of parentWidget()
, outside contentsMargins()
. All child widgets are placed below the bottom edge of the menu bar.
See also
- PySide6.QtWidgets.QLayout.setSizeConstraint(arg__1)#
- Parameters:
arg__1 –
SizeConstraint
See also
Setter of property sizeConstraint
.
Setter of property spacing
.
- PySide6.QtWidgets.QLayout.sizeConstraint()#
- Return type:
See also
Getter of property sizeConstraint
.
- PySide6.QtWidgets.QLayout.spacing()#
- Return type:
int
See also
Getter of property spacing
.
- abstract PySide6.QtWidgets.QLayout.takeAt(index)#
- Parameters:
index – int
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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:
- PySide6.QtWidgets.QLayout.totalHeightForWidth(w)#
- Parameters:
w – int
- Return type:
int
- PySide6.QtWidgets.QLayout.totalMaximumSize()#
- Return type:
- PySide6.QtWidgets.QLayout.totalMinimumHeightForWidth(w)#
- Parameters:
w – int
- Return type:
int
- PySide6.QtWidgets.QLayout.totalMinimumSize()#
- Return type:
- PySide6.QtWidgets.QLayout.totalSizeHint()#
- Return type:
- PySide6.QtWidgets.QLayout.unsetContentsMargins()#
Unsets any user-defined margins around the layout. The layout will use the default values provided by the style.
See also
Reset function of property contentsMargins
.
- PySide6.QtWidgets.QLayout.update()#
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()
- PySide6.QtWidgets.QLayout.widgetEvent(arg__1)#
- Parameters:
arg__1 –
PySide6.QtCore.QEvent