CopperSpice API
1.9.2
|
The QLayout class is the base class of geometry managers. More...
Public Types | |
enum | SizeConstraint |
Public Methods | |
QLayout () | |
QLayout (QWidget *parent) | |
bool | activate () |
virtual void | addItem (QLayoutItem *item) = 0 |
void | addWidget (QWidget *w) |
QMargins | contentsMargins () const |
QRect | contentsRect () const |
QSizePolicy::ControlTypes | controlTypes () const override |
virtual int | count () const = 0 |
Qt::Orientations | expandingDirections () const override |
QRect | geometry () const override |
void | getContentsMargins (int *left, int *top, int *right, int *bottom) const |
virtual int | indexOf (QWidget *widget) const |
void | invalidate () override |
bool | isEmpty () const override |
bool | isEnabled () const |
virtual QLayoutItem * | itemAt (int index) const = 0 |
QLayout * | layout () override |
int | margin () const |
QSize | maximumSize () const override |
QWidget * | menuBar () const |
QSize | minimumSize () const override |
QWidget * | parentWidget () const |
void | removeItem (QLayoutItem *item) |
void | removeWidget (QWidget *widget) |
virtual QLayoutItem * | replaceWidget (QWidget *from, QWidget *to, Qt::FindChildOptions options=Qt::FindChildrenRecursively) |
bool | setAlignment (QLayout *layout, Qt::Alignment alignment) |
void | setAlignment (Qt::Alignment alignment) |
bool | setAlignment (QWidget *widget, Qt::Alignment alignment) |
void | setContentsMargins (const QMargins &margins) |
void | setContentsMargins (int left, int top, int right, int bottom) |
void | setEnabled (bool enable) |
void | setGeometry (const QRect &rect) override |
void | setMargin (int margin) |
void | setMenuBar (QWidget *widget) |
void | setSizeConstraint (SizeConstraint constraint) |
void | setSpacing (int spacing) |
SizeConstraint | sizeConstraint () const |
int | spacing () const |
virtual QLayoutItem * | takeAt (int index) = 0 |
void | update () |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Public Methods inherited from QLayoutItem | |
QLayoutItem (Qt::Alignment alignment=Qt::Alignment ()) | |
virtual | ~QLayoutItem () |
Qt::Alignment | alignment () const |
virtual bool | hasHeightForWidth () const |
virtual int | heightForWidth (int width) const |
virtual int | minimumHeightForWidth (int width) const |
void | setAlignment (Qt::Alignment alignment) |
virtual QSize | sizeHint () const = 0 |
virtual QSpacerItem * | spacerItem () |
virtual QWidget * | widget () |
Static Public Methods | |
static QSize | closestAcceptableSize (const QWidget *widget, const QSize &size) |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Protected Methods | |
void | addChildLayout (QLayout *layout) |
void | addChildWidget (QWidget *widget) |
QRect | alignmentRect (const QRect &rect) const |
void | childEvent (QChildEvent *event) override |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Properties | |
margin | |
sizeConstraint | |
spacing | |
Properties inherited from QObject | |
objectName | |
Friends | |
class | QWidget |
Additional Inherited Members | |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Slots inherited from QObject | |
void | deleteLater () |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QLayout class is the base class of geometry managers. This is an abstract base class which is inherited by QBoxLayout, QGridLayout, QFormLayout, and QStackedLayout.
To create a custom layout manager inherit from this class and then implement the methods addItem(), sizeHint(), setGeometry(), itemAt() and takeAt(). You should also implement minimumSize() to ensure your layout is not resized to zero size if there is too little space. To support children whose heights depend on their widths, implement hasHeightForWidth() and heightForWidth().
Geometry management stops when the layout manager is deleted.
The possible values are shown in the following table.
Constant | Value | Description |
---|---|---|
QLayout::SetDefaultConstraint | 0 | The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size. |
QLayout::SetFixedSize | 3 | The main widget's size is set to sizeHint(); it can not be resized at all. |
QLayout::SetMinimumSize | 2 | The main widget's minimum size is set to minimumSize(); it can not be smaller. |
QLayout::SetMaximumSize | 4 | The main widget's maximum size is set to maximumSize(); it can not be larger. |
QLayout::SetMinAndMaxSize | 5 | The main widget's minimum size is set to minimumSize() and its maximum size is set to maximumSize(). |
QLayout::SetNoConstraint | 1 | The widget is not constrained. |
QLayout::QLayout | ( | QWidget * | parent | ) |
Constructs a new top-level QLayout, with the given parent which can not be a nullptr. There can be only one top-level layout for a widget. It is returned by QWidget::layout().
QLayout::QLayout | ( | ) |
Constructs a new child QLayout. This layout has to be inserted into another layout before geometry management will work.
bool QLayout::activate | ( | ) |
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.
|
protected |
This method is called from addLayout() and insertLayout() to add layout as a sub-layout.
|
protected |
This method is called from addWidget() to add widget as a managed widget of a layout.
If widget is already managed by a layout, this method will give a warning and remove the widget from that layout. This method must be called before adding widgets to the layout's data structure.
|
pure virtual |
Implemented in a subclasses to add a new item. This method is not usually called in application code. To add a widget to a layout use addWidget(). To add a child layout use addLayout() provided by the relevant QLayout subclass.
Implemented in QFormLayout::addItem(), QGridLayout::addItem(), QStackedLayout::addItem(), QBoxLayout::addItem()
void QLayout::addWidget | ( | QWidget * | w | ) |
Adds widget w to the current layout in a manner specific to the layout.
Returns the rectangle that should be covered when the geometry of this layout is set to rect, provided that this layout supports setAlignment(). The result is derived from sizeHint() and expanding(). It is never larger than rect.
|
overrideprotected |
Reimplemented from QObject::childEvent()
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size.
QMargins QLayout::contentsMargins | ( | ) | const |
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.
QRect QLayout::contentsRect | ( | ) | const |
Returns the layout's geometry() rectangle, but taking into account the contents margins.
|
overridevirtual |
Returns the control type(s) for the layout item. For a QWidgetItem, the control type comes from the widget's size policy; for a QLayoutItem, the control types is derived from the layout's contents.
Reimplemented from QLayoutItem::controlTypes()
|
pure virtual |
Must be implemented in subclasses to return the number of items in the layout.
Implemented in QFormLayout::count(), QGridLayout::count(), QBoxLayout::count(), QStackedLayout::count()
|
overridevirtual |
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 widget's size policies.
Implements QLayoutItem::expandingDirections()
|
overridevirtual |
Implements QLayoutItem::geometry()
void QLayout::getContentsMargins | ( | int * | left, |
int * | top, | ||
int * | right, | ||
int * | bottom | ||
) | const |
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.
Default values are PM_LayoutLeftMargin, PM_LayoutTopMargin, PM_LayoutRightMargin, and PM_LayoutBottomMargin.
|
virtual |
Searches for 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().
|
overridevirtual |
Reimplemented from QLayoutItem::invalidate()
|
overridevirtual |
Implements QLayoutItem::isEmpty()
bool QLayout::isEnabled | ( | ) | const |
Returns true if the layout is enabled, otherwise returns false.
|
pure virtual |
Must be implemented in subclasses to return the layout item at index. If there is no such item, the method must return a nullptr. Items are numbered consecutively starting from 0. If an item is deleted, other items will be renumbered.
This method 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.
Implemented in QFormLayout::itemAt(), QGridLayout::itemAt(), QBoxLayout::itemAt(), QStackedLayout::itemAt()
|
overridevirtual |
Reimplemented from QLayoutItem::layout()
int QLayout::margin | ( | ) | const |
Returns the value of the property.
|
overridevirtual |
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 does not include the space required by QWidget::setContentsMargins() or menuBar(). The default implementation allows unlimited resizing.
Implements QLayoutItem::maximumSize()
QWidget * QLayout::menuBar | ( | ) | const |
Returns the menu bar set for this layout or a nullptr if no menu bar is set.
|
overridevirtual |
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 does not include the space required by QWidget::setContentsMargins() or menuBar(). The default implementation allows unlimited resizing.
Implements QLayoutItem::minimumSize()
Reimplemented in QStackedLayout::minimumSize()
QWidget * QLayout::parentWidget | ( | ) | const |
Returns the parent widget of this layout or a nullptr 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.
void QLayout::removeItem | ( | QLayoutItem * | item | ) |
Removes the given 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).
void QLayout::removeWidget | ( | QWidget * | widget | ) |
Removes the 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.
|
virtual |
Searches for widget from and replaces it with widget to. If the given from widget is found, this method returns its layout item. If nothing is found a nullptr is returned. If options contains Qt::FindChildrenRecursively then sub-layouts are searched. All other flags in options are ignored. The returned item 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 from widget is no longer managed by the layout and may need to be deleted or hidden. The parent of the from widget is not unchanged.
This method works for the built in layouts but might not work for custom layouts.
bool QLayout::setAlignment | ( | QLayout * | layout, |
Qt::Alignment | alignment | ||
) |
Sets the alignment for the layout to alignment and returns true if layout is found in this QLayout (not including child layouts), otherwise returns false.
|
using |
Sets the alignment of this item to alignment. Item alignment is only supported by some child classes.
bool QLayout::setAlignment | ( | QWidget * | widget, |
Qt::Alignment | alignment | ||
) |
Sets the alignment for widget to alignment and returns true if widget is found in this layout (not including child layouts), otherwise returns false.
void QLayout::setContentsMargins | ( | const QMargins & | margins | ) |
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.
void QLayout::setContentsMargins | ( | int | left, |
int | top, | ||
int | right, | ||
int | bottom | ||
) |
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.
Default values are PM_LayoutLeftMargin, PM_LayoutTopMargin, PM_LayoutRightMargin, and PM_LayoutBottomMargin.
void QLayout::setEnabled | ( | bool | enable | ) |
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.
|
overridevirtual |
Implements QLayoutItem::setGeometry()
Reimplemented in QStackedLayout::setGeometry()
void QLayout::setMargin | ( | int | margin | ) |
Sets the value of the property to margin.
void QLayout::setMenuBar | ( | QWidget * | widget | ) |
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.
void QLayout::setSizeConstraint | ( | SizeConstraint | constraint | ) |
Sets the value of the property to constraint.
void QLayout::setSpacing | ( | int | spacing | ) |
Sets the value of the property to spacing.
SizeConstraint QLayout::sizeConstraint | ( | ) | const |
Returns the value of the property.
int QLayout::spacing | ( | ) | const |
Returns the value of the property.
|
pure virtual |
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 method must do nothing and return a nullptr. 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:
Implemented in QFormLayout::takeAt(), QGridLayout::takeAt(), QBoxLayout::takeAt(), QStackedLayout::takeAt()
void 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.
|
deprecated |
Use setContentsMargins() and getContentsMargins() instead.
Properties | Class Methods |
---|---|
read | margin |
write | setMargin |
|
This property holds the resize mode of the layout. The default mode is SetDefaultConstraint.
Properties | Class Methods |
---|---|
read | sizeConstraint |
write | setSizeConstraint |
|
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 this case spacing() returns -1.
Properties | Class Methods |
---|---|
read | spacing |
write | setSpacing |