PythonQt.QtGui.QFormLayout
QFormLayout
PythonQtInstanceWrapper object
Native bases: PythonQtInstanceWrapper
Supplemental documentation: Qt 5 reference:
Detailed Description
QFormLayout is a convenience layout class that lays out its children in a two-column form. The left column consists of labels and the right column consists of "field" widgets (line editors, spin boxes, etc.).
Traditionally, such two-column form layouts were achieved using QGridLayout. QFormLayout is a higher-level alternative that provides the following advantages:
- Adherence to the different platform's look and feel guidelines.
For example, the macOS Aqua and KDE guidelines specify that the labels should be right-aligned, whereas Windows and GNOME applications normally use left-alignment. - Support for wrapping long rows.
For devices with small displays, QFormLayout can be set to wrap long rows, or even to wrap all rows. - Convenient API for creating label--field pairs.
The addRow() overload that takes a QString and a QWidget * creates a QLabel behind the scenes and automatically set up its buddy. We can then write code like this:
QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(tr("&Name:"), nameLineEdit);
formLayout->addRow(tr("&Email:"), emailLineEdit);
formLayout->addRow(tr("&Age:"), ageSpinBox);
setLayout(formLayout);
Compare this with the following code, written using QGridLayout:
nameLabel = new QLabel(tr("&Name:"));
nameLabel->setBuddy(nameLineEdit);
emailLabel = new QLabel(tr("&Name:"));
emailLabel->setBuddy(emailLineEdit);
ageLabel = new QLabel(tr("&Name:"));
ageLabel->setBuddy(ageSpinBox);
QGridLayout *gridLayout = new QGridLayout;
gridLayout->addWidget(nameLabel, 0, 0);
gridLayout->addWidget(nameLineEdit, 0, 1);
gridLayout->addWidget(emailLabel, 1, 0);
gridLayout->addWidget(emailLineEdit, 1, 1);
gridLayout->addWidget(ageLabel, 2, 0);
gridLayout->addWidget(ageSpinBox, 2, 1);
setLayout(gridLayout);
The table below shows the default appearance in different styles.
| QCommonStyle derived styles (except QPlastiqueStyle) | QMacStyle | QPlastiqueStyle | Qt Extended styles |
|---|---|---|---|
| Traditional style used for Windows, GNOME, and earlier versions of KDE. Labels are left aligned, and expanding fields grow to fill the available space. (This normally corresponds to what we would get using a two-column QGridLayout.) | Style based on the macOS Aqua guidelines. Labels are right-aligned, the fields don't grow beyond their size hint, and the form is horizontally centered. | Recommended style for KDE applications. Similar to MacStyle, except that the form is left-aligned and all fields grow to fill the available space. | Default style for Qt Extended styles. Labels are right-aligned, expanding fields grow to fill the available space, and row wrapping is enabled for long lines. |
The form styles can be also be overridden individually by calling setLabelAlignment(), setFormAlignment(), setFieldGrowthPolicy(), and setRowWrapPolicy(). For example, to simulate the form layout appearance of QMacStyle on all platforms, but with left-aligned labels, you could write:
formLayout->setRowWrapPolicy(QFormLayout::DontWrapRows);
formLayout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
formLayout->setFormAlignment(Qt::AlignHCenter | Qt::AlignTop);
formLayout->setLabelAlignment(Qt::AlignLeft);
Source: https://doc.qt.io/archives/qt-5.15/qformlayout.html
Complete member index
Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.
| Member | Kind | Signature | Summary |
|---|---|---|---|
AllNonFixedFieldsGrow |
attribute | Any |
|
DontWrapRows |
attribute | Any |
|
ExpandingFieldsGrow |
attribute | Any |
|
FieldGrowthPolicy |
attribute | type |
Convert a number or string to an integer, or return 0 if no arguments are given. |
FieldRole |
attribute | Any |
|
FieldsStayAtSizeHint |
attribute | Any |
|
ItemRole |
attribute | type |
Convert a number or string to an integer, or return 0 if no arguments are given. |
LabelRole |
attribute | Any |
|
RowWrapPolicy |
attribute | type |
Convert a number or string to an integer, or return 0 if no arguments are given. |
SetDefaultConstraint |
attribute | Any |
(shared captured text) |
SetFixedSize |
attribute | Any |
(shared captured text) |
SetMaximumSize |
attribute | Any |
(shared captured text) |
SetMinAndMaxSize |
attribute | Any |
(shared captured text) |
SetMinimumSize |
attribute | Any |
(shared captured text) |
SetNoConstraint |
attribute | Any |
(shared captured text) |
SizeConstraint |
attribute | type |
Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text) |
SpanningRole |
attribute | Any |
|
WrapAllRows |
attribute | Any |
|
WrapLongRows |
attribute | Any |
|
__init__ |
function | (self, *args: Any, **kwargs: Any) -> None |
Native constructor; consult class documentation for supported overloads. (shared captured text) |
activate |
function | (self) -> bool |
X.activate() -> bool (shared captured text) |
addChildLayout |
function | (self, l: Any) -> Any |
(shared captured text) |
addChildWidget |
function | (self, w: Any) -> Any |
(shared captured text) |
addItem |
function | (self, item: Any) -> None |
Reimplements: [QLayout::addItem](https://doc.qt.io/archives/qt-5.15/qlayout.html#addItem)(QLayoutItem *item). |
addRow |
function | (self, label: Any, field: Any) -> None |
X.addRow(label, field) |
addWidget |
function | (self, w: Any) -> Any |
|
adoptLayout |
function | (self, layout: Any) -> bool |
X.adoptLayout(layout) -> bool (shared captured text) |
alignment |
function | (self) -> Any |
(shared captured text) |
alignmentRect |
function | (self, arg__1: Any) -> Any |
X.alignmentRect(arg__1) -> PythonQt.QtCore.QRect (shared captured text) |
blockSignals |
function | (self, b: Any) -> bool |
X.blockSignals(b) -> bool (shared captured text) |
childEvent |
function | (self, e: Any) -> Any |
(shared captured text) |
children |
function | (self) -> tuple |
X.children() -> tuple (shared captured text) |
className |
function | (self, *args: Any, **kwargs: Any) -> Any |
Return the classname of the object (shared captured text) |
closestAcceptableSize |
function | (self, w: Any, s: Any) -> Any |
X.closestAcceptableSize(w, s) -> PythonQt.QtCore.QSize (shared captured text) |
connect |
function | (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool |
X.connect(signal, receiver, slot, type) -> bool (shared captured text) |
contentsMargins |
function | (self) -> Any |
X.contentsMargins() -> PythonQt.QtGui.QMargins (shared captured text) |
contentsRect |
function | (self) -> Any |
X.contentsRect() -> PythonQt.QtCore.QRect (shared captured text) |
controlTypes |
function | (self) -> Any |
(shared captured text) |
count |
function | (self) -> int |
X.count() -> int |
customEvent |
function | (self, event: Any) -> Any |
(shared captured text) |
delete |
function | (self, *args: Any, **kwargs: Any) -> Any |
Deletes the C++ object (at your own risk, my friend!) (shared captured text) |
deleteLater |
function | (self) -> Any |
(shared captured text) |
destroyed |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtGui.QFormLayout.destroyed; argument details are not documented. |
disconnect |
function | (self, signal: Any, receiver: Any, slot: Any) -> bool |
X.disconnect(signal, receiver, slot) -> bool (shared captured text) |
dumpObjectInfo |
function | (self) -> Any |
(shared captured text) |
dumpObjectTree |
function | (self) -> Any |
(shared captured text) |
dynamicPropertyNames |
function | (self) -> Any |
(shared captured text) |
event |
function | (self, event: Any) -> bool |
X.event(event) -> bool (shared captured text) |
eventFilter |
function | (self, watched: Any, event: Any) -> bool |
X.eventFilter(watched, event) -> bool (shared captured text) |
expandingDirections |
function | (self) -> Any |
Reimplements: [QLayout::expandingDirections](https://doc.qt.io/archives/qt-5.15/qlayout.html#expandingDirections)() const. |
fieldGrowthPolicy |
attribute | Any |
This property holds the way in which the form's fields grow |
findChild |
function | (self, type: Any, name: Any) -> Any |
X.findChild(type, name) -> PythonQt.private.QObject (shared captured text) |
findChildren |
function | (self, type: Any, name: Any) -> tuple |
X.findChildren(type, name) -> tuple (shared captured text) |
formAlignment |
attribute | Any |
This property holds the alignment of the form layout's contents within the layout's geometry |
geometry |
function | (self) -> Any |
X.geometry() -> PythonQt.QtCore.QRect (shared captured text) |
getItemPosition |
function | (self, index: int, rowPtr: Any, rolePtr: Any) -> int |
X.getItemPosition(index, rowPtr, rolePtr) |
getLayoutPosition |
function | (self, layout: Any, rowPtr: Any, rolePtr: Any) -> int |
X.getLayoutPosition(layout, rowPtr, rolePtr) |
getWidgetPosition |
function | (self, widget: Any, rowPtr: Any, rolePtr: Any) -> int |
X.getWidgetPosition(widget, rowPtr, rolePtr) |
hasHeightForWidth |
function | (self) -> bool |
X.hasHeightForWidth() -> bool |
heightForWidth |
function | (self, width: int) -> int |
X.heightForWidth(width) -> int |
help |
function | (self, *args: Any, **kwargs: Any) -> Any |
Shows the help of available methods for this class (shared captured text) |
horizontalSpacing |
attribute | int |
This property holds the spacing between widgets that are laid out side by side |
indexOf |
function | (self, arg__1: Any) -> int |
X.indexOf(arg__1) -> int (shared captured text) |
inherits |
function | (self, *args: Any, **kwargs: Any) -> Any |
Returns if the class inherits or is of given type name (shared captured text) |
insertRow |
function | (self, row: int, label: Any, field: Any) -> None |
X.insertRow(row, label, field) |
installEventFilter |
function | (self, filterObj: Any) -> Any |
(shared captured text) |
invalidate |
function | (self) -> None |
Reimplements: [QLayout::invalidate](https://doc.qt.io/archives/qt-5.15/qlayout.html#invalidate)(). |
isEmpty |
function | (self) -> bool |
X.isEmpty() -> bool (shared captured text) |
isEnabled |
function | (self) -> bool |
X.isEnabled() -> bool (shared captured text) |
isSignalConnected |
function | (self, signal: Any) -> bool |
X.isSignalConnected(signal) -> bool (shared captured text) |
isWidgetType |
function | (self) -> bool |
X.isWidgetType() -> bool (shared captured text) |
isWindowType |
function | (self) -> bool |
X.isWindowType() -> bool (shared captured text) |
itemAt |
function | (self, index: Any) -> Any |
X.itemAt(index) -> PythonQt.QtGui.QLayoutItem |
killTimer |
function | (self, id: Any) -> Any |
(shared captured text) |
labelAlignment |
attribute | Any |
This property holds the horizontal alignment of the labels |
labelForField |
function | (self, field: Any) -> Any |
X.labelForField(field) -> PythonQt.QtGui.QWidget |
layout |
function | (self) -> Any |
X.layout() -> PythonQt.QtGui.QLayout (shared captured text) |
margin |
attribute | Any |
(shared captured text) |
maximumSize |
function | (self) -> Any |
X.maximumSize() -> PythonQt.QtCore.QSize |
menuBar |
function | (self) -> Any |
X.menuBar() -> PythonQt.QtGui.QWidget (shared captured text) |
metaObject |
function | (self) -> Any |
X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text) |
minimumHeightForWidth |
function | (self, arg__1: Any) -> int |
X.minimumHeightForWidth(arg__1) -> int |
minimumSize |
function | (self) -> Any |
X.minimumSize() -> PythonQt.QtCore.QSize |
moveToThread |
function | (self, thread: Any) -> Any |
(shared captured text) |
objectName |
attribute | Any |
(shared captured text) |
objectNameChanged |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtGui.QFormLayout.objectNameChanged; argument details are not documented. |
parent |
function | (self) -> Any |
X.parent() -> PythonQt.private.QObject (shared captured text) |
parentWidget |
function | (self) -> Any |
X.parentWidget() -> PythonQt.QtGui.QWidget (shared captured text) |
property |
function | (self, name: Any) -> Any |
X.property(name) -> object (shared captured text) |
removeEventFilter |
function | (self, obj: Any) -> Any |
(shared captured text) |
removeItem |
function | (self, arg__1: Any) -> Any |
(shared captured text) |
removeWidget |
function | (self, w: Any) -> Any |
(shared captured text) |
replaceWidget |
function | (self, *args: Any, **kwargs: Any) -> Any |
X.replaceWidget(from, to, options) -> PythonQt.QtGui.QLayoutItem (shared captured text) |
rowCount |
function | (self) -> int |
X.rowCount() -> int |
rowWrapPolicy |
attribute | Any |
This property holds the way in which the form's rows wrap |
sender |
function | (self) -> Any |
X.sender() -> PythonQt.private.QObject (shared captured text) |
senderSignalIndex |
function | (self) -> int |
X.senderSignalIndex() -> int (shared captured text) |
setAlignment |
function | (self, l: Any, alignment: Any) -> bool |
X.setAlignment(l, alignment) -> bool (shared captured text) |
setContentsMargins |
function | (self, left: Any, top: Any, right: Any, bottom: Any) -> Any |
X.setContentsMargins(left, top, right, bottom) (shared captured text) |
setEnabled |
function | (self, arg__1: Any) -> Any |
(shared captured text) |
setFieldGrowthPolicy |
function | (self, policy: Any) -> None |
|
setFormAlignment |
function | (self, alignment: Any) -> None |
|
setGeometry |
function | (self, rect: Any) -> None |
Reimplements: [QLayout::setGeometry](https://doc.qt.io/archives/qt-5.15/qlayout.html#setGeometry)(const QRect \&r). |
setHorizontalSpacing |
function | (self, spacing: int) -> None |
|
setItem |
function | (self, row: int, role: Any, item: Any) -> None |
X.setItem(row, role, item) |
setLabelAlignment |
function | (self, alignment: Any) -> None |
|
setLayout |
function | (self, row: int, role: Any, layout: Any) -> None |
X.setLayout(row, role, layout) |
setMargin |
function | (self, arg__1: Any) -> Any |
(shared captured text) |
setMenuBar |
function | (self, w: Any) -> Any |
(shared captured text) |
setObjectName |
function | (self, name: Any) -> Any |
(shared captured text) |
setParent |
function | (self, parent: Any) -> Any |
(shared captured text) |
setProperty |
function | (self, name: Any, value: Any) -> bool |
X.setProperty(name, value) -> bool (shared captured text) |
setRowWrapPolicy |
function | (self, policy: Any) -> None |
|
setSizeConstraint |
function | (self, arg__1: Any) -> Any |
(shared captured text) |
setSpacing |
function | (self, arg__1: int) -> None |
This function sets both the vertical and horizontal spacing to spacing. |
setVerticalSpacing |
function | (self, spacing: int) -> None |
|
setWidget |
function | (self, row: int, role: Any, widget: Any) -> None |
X.setWidget(row, role, widget) |
signalsBlocked |
function | (self) -> bool |
X.signalsBlocked() -> bool (shared captured text) |
sizeConstraint |
attribute | Any |
(shared captured text) |
sizeHint |
function | (self) -> Any |
X.sizeHint() -> PythonQt.QtCore.QSize |
spacerItem |
function | (self) -> Any |
X.spacerItem() -> PythonQt.QtGui.QSpacerItem (shared captured text) |
spacing |
attribute | int |
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwise it returns -1. |
startTimer |
function | (self, interval: Any, timerType: Any) -> int |
X.startTimer(interval, timerType) -> int (shared captured text) |
takeAt |
function | (self, index: int) -> Any |
X.takeAt(index) -> PythonQt.QtGui.QLayoutItem |
thread |
function | (self) -> Any |
(shared captured text) |
timerEvent |
function | (self, event: Any) -> Any |
(shared captured text) |
totalHeightForWidth |
function | (self, w: Any) -> int |
X.totalHeightForWidth(w) -> int (shared captured text) |
totalMaximumSize |
function | (self) -> Any |
X.totalMaximumSize() -> PythonQt.QtCore.QSize (shared captured text) |
totalMinimumSize |
function | (self) -> Any |
X.totalMinimumSize() -> PythonQt.QtCore.QSize (shared captured text) |
totalSizeHint |
function | (self) -> Any |
X.totalSizeHint() -> PythonQt.QtCore.QSize (shared captured text) |
tr |
function | (self, text: Any, ambig: Any, n: Any) -> str |
X.tr(text, ambig, n) -> str (shared captured text) |
update |
function | (self) -> Any |
(shared captured text) |
verticalSpacing |
attribute | int |
This property holds the spacing between widgets that are laid out vertically |
widget |
function | (self) -> Any |
X.widget() -> PythonQt.QtGui.QWidget (shared captured text) |
widgetEvent |
function | (self, arg__1: Any) -> Any |
(shared captured text) |