|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QLayout
com.trolltech.qt.gui.QFormLayout
public class QFormLayout
The QFormLayout class manages forms of input widgets and their associated labels. 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:
For example, the Mac OS X Aqua and KDE guidelines specify that the labels should be right-aligned, whereas Windows and GNOME applications normally use left-alignment.
For devices with small displays, QFormLayout can be set to wrap long rows
, or even to wrap all rows
.
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("Email:")); emailLabel.setBuddy(emailLineEdit); ageLabel = new QLabel(tr("Age:")); 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);
QCommonStyle derived styles (except QPlastiqueStyle ) | QPlastiqueStyle | ||
---|---|---|---|
![]() | ![]() | ![]() | ![]() |
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 Mac OS X 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. |
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.setLabelAlignment(Qt.AlignmentFlag.AlignLeft);
QGridLayout
, QBoxLayout
, and QStackedLayout
.
Nested Class Summary | |
---|---|
static class |
QFormLayout.FieldGrowthPolicy
This enum specifies the different policies that can be used to control the way in which the form's fields grow. |
static class |
QFormLayout.ItemRole
This enum specifies the types of widgets (or other layout items) that may appear in a row. |
static class |
QFormLayout.RowWrapPolicy
This enum specifies the different policies that can be used to control the way in which the form's rows wrap. |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QLayout |
---|
QLayout.SizeConstraint |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QFormLayout()
Constructs a new form layout with the given parent widget. |
|
QFormLayout(QWidget parent)
Constructs a new form layout with the given parent widget. |
Method Summary | |
---|---|
void |
addRow(QLayout layout)
This is an overloaded member function, provided for convenience. |
void |
addRow(QWidget widget)
This is an overloaded member function, provided for convenience. |
void |
addRow(QWidget label,
QWidget field)
Adds a new row to the bottom of this form layout, with the given label and field. |
void |
addRow(java.lang.String labelText,
QLayout field)
This is an overloaded member function, provided for convenience. |
void |
addRow(java.lang.String labelText,
QWidget field)
This is an overloaded member function, provided for convenience. |
QFormLayout.FieldGrowthPolicy |
fieldGrowthPolicy()
This property holds the way in which the form's fields grow. |
Qt.Alignment |
formAlignment()
This property holds the alignment of the form layout's contents within the layout's geometry. |
QPair |
getItemPosition(int index)
Retrieves the row and role (column) of the item at the specified index. |
QPair |
getLayoutPosition(QLayout layout)
Retrieves the row and role (column) of the specified child layout. |
QPair |
getWidgetPosition(QWidget widget)
Retrieves the row and role (column) of the specified widget in the layout. |
int |
horizontalSpacing()
This property holds the spacing between widgets that are laid out side by side. |
void |
insertRow(int row,
QLayout layout)
This is an overloaded member function, provided for convenience. |
void |
insertRow(int row,
QWidget widget)
This is an overloaded member function, provided for convenience. |
void |
insertRow(int row,
QWidget label,
QLayout field)
Inserts a new row at position row in this form layout, with the given label and field. |
void |
insertRow(int row,
QWidget label,
QWidget field)
Inserts a new row at position row in this form layout, with the given label and field. |
void |
insertRow(int row,
java.lang.String labelText,
QLayout field)
This is an overloaded member function, provided for convenience. |
void |
insertRow(int row,
java.lang.String labelText,
QWidget field)
This is an overloaded member function, provided for convenience. |
QLayoutItemInterface |
itemAt(int row,
QFormLayout.ItemRole role)
Returns the layout item in the given row with the specified role (column). |
Qt.Alignment |
labelAlignment()
This property holds the horizontal alignment of the labels. |
QWidget |
labelForField(QLayout field)
This is an overloaded member function, provided for convenience. |
QWidget |
labelForField(QWidget field)
Returns the label associated with the given field. |
int |
rowCount()
Returns the number of rows in the form. |
QFormLayout.RowWrapPolicy |
rowWrapPolicy()
This property holds the way in which the form's rows wrap. |
void |
setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy policy)
This property holds the way in which the form's fields grow. |
void |
setFormAlignment(Qt.Alignment alignment)
This property holds the alignment of the form layout's contents within the layout's geometry. |
void |
setFormAlignment(Qt.AlignmentFlag[] alignment)
|
void |
setHorizontalSpacing(int spacing)
This property holds the spacing between widgets that are laid out side by side. |
void |
setItem(int row,
QFormLayout.ItemRole role,
QLayoutItem item)
Sets the item in the given row for the given role to item, extending the layout with empty rows if necessary. |
void |
setLabelAlignment(Qt.Alignment alignment)
This property holds the horizontal alignment of the labels. |
void |
setLabelAlignment(Qt.AlignmentFlag[] alignment)
|
void |
setLayout(int row,
QFormLayout.ItemRole role,
QLayout layout)
Sets the sub-layout in the given row for the given role to layout, extending the form layout with empty rows if necessary. |
void |
setRowWrapPolicy(QFormLayout.RowWrapPolicy policy)
This property holds the way in which the form's rows wrap. |
void |
setSpacing(int arg__1)
This function sets both the vertical and horizontal spacing to spacing. |
void |
setVerticalSpacing(int spacing)
This property holds the spacing between widgets that are laid out vertically. |
void |
setWidget(int row,
QFormLayout.ItemRole role,
QWidget widget)
Sets the widget in the given row for the given role to widget, extending the layout with empty rows if necessary. |
int |
spacing()
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwise it returns -1. |
int |
verticalSpacing()
This property holds the spacing between widgets that are laid out vertically. |
Methods inherited from class com.trolltech.qt.gui.QLayout |
---|
activate, addChildLayout, addChildWidget, addItem, addWidget, alignment, alignmentRect, closestAcceptableSize, contentsRect, controlTypes, count, expandingDirections, geometry, getContentsMargins, hasHeightForWidth, heightForWidth, indexOf, invalidate, isEmpty, isEnabled, itemAt, layout, maximumSize, menuBar, minimumHeightForWidth, minimumSize, parentWidget, removeItem, removeWidget, setAlignment, setAlignment, setAlignment, setAlignment, setAlignment, setContentsMargins, setContentsMargins, setEnabled, setGeometry, setMargin, setMenuBar, setSizeConstraint, setWidgetSpacing, sizeConstraint, sizeHint, spacerItem, takeAt, update, widget, widgetSpacing |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QFormLayout()
QWidget::setLayout()
.
public QFormLayout(QWidget parent)
QWidget::setLayout()
.
Method Detail |
---|
public final void addRow(QLayout layout)
Adds the specified layout at the end of this form layout. The layout spans both columns.
public final void addRow(QWidget label, QWidget field)
insertRow()
.
public final void addRow(QWidget widget)
Adds the specified widget at the end of this form layout. The widget spans both columns.
public final void addRow(java.lang.String labelText, QLayout field)
This overload automatically creates a QLabel
behind the scenes with labelText as its text.
public final void addRow(java.lang.String labelText, QWidget field)
This overload automatically creates a QLabel
behind the scenes with labelText as its text. The field is set as the new QLabel
's buddy
.
public final QFormLayout.FieldGrowthPolicy fieldGrowthPolicy()
FieldsStayAtSizeHint
; for QCommonStyle
derived styles (like Plastique and Windows), the default is ExpandingFieldsGrow
; for Qt Extended styles, the default is AllNonFixedFieldsGrow
. If none of the fields can grow and the form is resized, extra space is distributed according to the current form alignment
.
formAlignment
, and rowWrapPolicy
.
public final Qt.Alignment formAlignment()
Qt::AlignHCenter
| Qt::AlignTop
; for the other styles, the default is Qt::AlignLeft
| Qt::AlignTop
. labelAlignment
, and rowWrapPolicy
.
public final int horizontalSpacing()
verticalSpacing
, QStyle::pixelMetric()
, and PM_LayoutHorizontalSpacing
.
public final void insertRow(int row, QLayout layout)
Inserts the specified layout at position row in this form layout. The layout spans both columns. If row is out of bounds, the widget is added at the end.
public final void insertRow(int row, QWidget label, QLayout field)
addRow()
.
public final void insertRow(int row, QWidget label, QWidget field)
addRow()
.
public final void insertRow(int row, QWidget widget)
Inserts the specified widget at position row in this form layout. The widget spans both columns. If row is out of bounds, the widget is added at the end.
public final void insertRow(int row, java.lang.String labelText, QLayout field)
This overload automatically creates a QLabel
behind the scenes with labelText as its text.
public final void insertRow(int row, java.lang.String labelText, QWidget field)
This overload automatically creates a QLabel
behind the scenes with labelText as its text. The field is set as the new QLabel
's buddy
.
public final QLayoutItemInterface itemAt(int row, QFormLayout.ItemRole role)
QLayout::itemAt()
, and setItem()
.
public final Qt.Alignment labelAlignment()
QCommonStyle
derived styles, except for QPlastiqueStyle
, the default is Qt::AlignLeft
; for the other styles, the default is Qt::AlignRight
. formAlignment
.
public final QWidget labelForField(QLayout field)
public final QWidget labelForField(QWidget field)
itemAt()
.
public final int rowCount()
QLayout::count()
.
public final QFormLayout.RowWrapPolicy rowWrapPolicy()
WrapLongRows
; for the other styles, the default is DontWrapRows
. If you want to display each label above its associated field (instead of next to it), set this property to WrapAllRows
.
fieldGrowthPolicy
.
public final void setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy policy)
FieldsStayAtSizeHint
; for QCommonStyle
derived styles (like Plastique and Windows), the default is ExpandingFieldsGrow
; for Qt Extended styles, the default is AllNonFixedFieldsGrow
. If none of the fields can grow and the form is resized, extra space is distributed according to the current form alignment
.
formAlignment
, and rowWrapPolicy
.
public final void setFormAlignment(Qt.AlignmentFlag[] alignment)
public final void setFormAlignment(Qt.Alignment alignment)
Qt::AlignHCenter
| Qt::AlignTop
; for the other styles, the default is Qt::AlignLeft
| Qt::AlignTop
. labelAlignment
, and rowWrapPolicy
.
public final void setHorizontalSpacing(int spacing)
verticalSpacing
, QStyle::pixelMetric()
, and PM_LayoutHorizontalSpacing
.
public final void setLabelAlignment(Qt.AlignmentFlag[] alignment)
public final void setLabelAlignment(Qt.Alignment alignment)
QCommonStyle
derived styles, except for QPlastiqueStyle
, the default is Qt::AlignLeft
; for the other styles, the default is Qt::AlignRight
. formAlignment
.
public final void setLayout(int row, QFormLayout.ItemRole role, QLayout layout)
If the cell is already occupied, the layout is not inserted and an error message is sent to the console.
Note: For most applications, addRow()
or insertRow()
should be used instead of setLayout()
.
setWidget()
.
public final void setRowWrapPolicy(QFormLayout.RowWrapPolicy policy)
WrapLongRows
; for the other styles, the default is DontWrapRows
. If you want to display each label above its associated field (instead of next to it), set this property to WrapAllRows
.
fieldGrowthPolicy
.
public final void setSpacing(int arg__1)
spacing()
, setVerticalSpacing()
, and setHorizontalSpacing()
.
public final void setVerticalSpacing(int spacing)
horizontalSpacing
, QStyle::pixelMetric()
, and PM_LayoutHorizontalSpacing
.
public final void setWidget(int row, QFormLayout.ItemRole role, QWidget widget)
If the cell is already occupied, the widget is not inserted and an error message is sent to the console.
Note: For most applications, addRow()
or insertRow()
should be used instead of setWidget()
.
setLayout()
.
public final int spacing()
setSpacing()
, verticalSpacing()
, and horizontalSpacing()
.
public final int verticalSpacing()
horizontalSpacing
, QStyle::pixelMetric()
, and PM_LayoutHorizontalSpacing
.
public final QPair getItemPosition(int index)
index
- The index of the item for which to retrieve the position.
public final QPair getLayoutPosition(QLayout layout)
layout
- The layout for which to retrieve the position.
public final QPair getWidgetPosition(QWidget widget)
widget
- The widget for which to retrieve the position.
public final void setItem(int row, QFormLayout.ItemRole role, QLayoutItem item)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |