Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Static Private Functions | Properties | Friends | List of all members
QLayout Class Referenceabstract

The QLayout class is the base class of geometry managers. More...

#include <qlayout.h>

Inheritance diagram for QLayout:
QObject QLayoutItem QBoxLayout QDockWidgetLayout QFormLayout QGridLayout QMainWindowLayout QStackedLayout QToolBarLayout QHBoxLayout QVBoxLayout QStackedLayoutHFW

Public Types

enum  SizeConstraint {
  SetDefaultConstraint, SetNoConstraint, SetMinimumSize, SetFixedSize,
  SetMaximumSize, SetMinAndMaxSize
}
 The possible values are: More...
 

Public Functions

bool activate ()
 Redoes the layout for parentWidget() if necessary. More...
 
virtual void addItem (QLayoutItem *)=0
 Implemented in subclasses to add an item. More...
 
void addWidget (QWidget *w)
 Adds widget w to this layout in a manner specific to the layout. More...
 
QMargins contentsMargins () const
 Returns the margins used around the layout. More...
 
QRect contentsRect () const
 Returns the layout's geometry() rectangle, but taking into account the contents margins. More...
 
virtual int count () const =0
 Must be implemented in subclasses to return the number of items in the layout. More...
 
Qt::Orientations expandingDirections () const
 Returns whether this layout can make use of more space than sizeHint(). More...
 
QRect geometry () const
 Reimplemented Function More...
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
virtual int indexOf (QWidget *) const
 Searches for widget widget in this layout (not including child layouts). More...
 
void invalidate ()
 Reimplemented Function More...
 
bool isEmpty () const
 Reimplemented Function More...
 
bool isEnabled () const
 Returns true if the layout is enabled; otherwise returns false. More...
 
virtual QLayoutItemitemAt (int index) const =0
 Must be implemented in subclasses to return the layout item at index. More...
 
QLayoutlayout ()
 Reimplemented Function More...
 
int margin () const
 
QSize maximumSize () const
 Returns the maximum size of this layout. More...
 
QWidgetmenuBar () const
 Returns the menu bar set for this layout, or 0 if no menu bar is set. More...
 
QSize minimumSize () const
 Returns the minimum size of this layout. More...
 
QWidgetparentWidget () const
 Returns the parent widget of this layout, or 0 if this layout is not installed on any widget. More...
 
 QLayout (QWidget *parent)
 Constructs a new top-level QLayout, with parent parent. More...
 
 QLayout ()
 Constructs a new child QLayout. More...
 
void removeItem (QLayoutItem *)
 Removes the layout item item from the layout. More...
 
void removeWidget (QWidget *w)
 Removes the widget widget from the layout. More...
 
bool setAlignment (QWidget *w, Qt::Alignment alignment)
 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. More...
 
bool setAlignment (QLayout *l, Qt::Alignment alignment)
 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. More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the left, top, right, and bottom margins to use around the layout. More...
 
void setContentsMargins (const QMargins &margins)
 Sets the margins to use around the layout. More...
 
void setEnabled (bool)
 Enables this layout if enable is true, otherwise disables it. More...
 
virtual void setGeometry (const QRect &)
 Reimplemented Function More...
 
void setMargin (int)
 
void setMenuBar (QWidget *w)
 Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins(). More...
 
void setSizeConstraint (SizeConstraint)
 
void setSpacing (int)
 
SizeConstraint sizeConstraint () const
 
int spacing () const
 
virtual QLayoutItemtakeAt (int index)=0
 Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. More...
 
int totalHeightForWidth (int w) const
 Also takes contentsMargins and menu bar into account. More...
 
QSize totalMaximumSize () const
 Also takes contentsMargins and menu bar into account. More...
 
QSize totalMinimumSize () const
 Also takes contentsMargins and menu bar into account. More...
 
QSize totalSizeHint () const
 Also takes contentsMargins and menu bar into account. More...
 
void update ()
 Updates the layout for parentWidget(). More...
 
 ~QLayout ()
 Destroys the layout, deleting all child layouts. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QLayoutItem
Qt::Alignment alignment () const
 Returns the alignment of this item. More...
 
QSizePolicy::ControlTypes controlTypes () const
 Returns the control type(s) for the layout item. More...
 
virtual bool hasHeightForWidth () const
 Returns true if this layout's preferred height depends on its width; otherwise returns false. More...
 
virtual int heightForWidth (int) const
 Returns the preferred height for this layout item, given the width w. More...
 
virtual int minimumHeightForWidth (int) const
 Returns the minimum height this widget needs for the given width, w. More...
 
 QLayoutItem (Qt::Alignment alignment=0)
 Constructs a layout item with an alignment. More...
 
void setAlignment (Qt::Alignment a)
 Sets the alignment of this item to alignment. More...
 
virtual QSize sizeHint () const =0
 Implemented in subclasses to return the preferred size of this item. More...
 
virtual QSpacerItemspacerItem ()
 If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise 0 is returned. More...
 
virtual QWidgetwidget ()
 If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned. More...
 
virtual ~QLayoutItem ()
 Destroys the QLayoutItem. More...
 

Static Public Functions

static QSize closestAcceptableSize (const QWidget *w, const QSize &s)
 Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Protected Functions

void addChildLayout (QLayout *l)
 This function is called from addLayout() or insertLayout() functions in subclasses to add layout l as a sub-layout. More...
 
void addChildWidget (QWidget *w)
 This function is called from addWidget() functions in subclasses to add w as a managed widget of a layout. More...
 
bool adoptLayout (QLayout *layout)
 
QRect alignmentRect (const QRect &) const
 Returns the rectangle that should be covered when the geometry of this layout is set to r, provided that this layout supports setAlignment(). More...
 
void childEvent (QChildEvent *e)
 Reimplemented Function More...
 
 QLayout (QLayoutPrivate &d, QLayout *, QWidget *)
 
void widgetEvent (QEvent *)
 Performs child widget layout when the parent widget is resized. More...
 
- Protected Functions inherited from QObject
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Static Private Functions

static void activateRecursiveHelper (QLayoutItem *item)
 

Properties

int margin
 the width of the outside border of the layout More...
 
SizeConstraint sizeConstraint
 the resize mode of the layout More...
 
int spacing
 the spacing between widgets inside the layout More...
 

Friends

class QApplicationPrivate
 
class QWidget
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QLayoutItem
Qt::Alignment align
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QLayout class is the base class of geometry managers.

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}

Definition at line 90 of file qlayout.h.

Enumerations

◆ SizeConstraint

The possible values are:

  • SetDefaultConstraint The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size.
  • SetFixedSize The main widget's size is set to sizeHint(); it cannot be resized at all.
  • SetMinimumSize The main widget's minimum size is set to minimumSize(); it cannot be smaller.
  • SetMaximumSize The main widget's maximum size is set to maximumSize(); it cannot be larger.
  • SetNoConstraint The widget is not constrained.
  • Auto
  • FreeResize
  • Minimum
  • Fixed
See also
setSizeConstraint()
Enumerator
SetDefaultConstraint 
SetNoConstraint 
SetMinimumSize 
SetFixedSize 
SetMaximumSize 
SetMinAndMaxSize 

Definition at line 100 of file qlayout.h.

100  {
104  SetFixedSize,
107 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
108  , Auto = SetDefaultConstraint,
109  FreeResize = SetNoConstraint,
110  Minimum = SetMinimumSize,
111  Fixed = SetFixedSize
112 #endif
113  };

Constructors and Destructors

◆ QLayout() [1/3]

QLayout::QLayout ( QWidget parent)

Constructs a new top-level QLayout, with parent parent.

parent may not be 0.

There can be only one top-level layout for a widget. It is returned by QWidget::layout().

Definition at line 113 of file qlayout.cpp.

114  : QObject(*new QLayoutPrivate, parent)
115 {
116  if (!parent)
117  return;
118  parent->setLayout(this);
119 }
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
Definition: qwidget.cpp:10104
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QLayout() [2/3]

QLayout::QLayout ( )

Constructs a new child QLayout.

This layout has to be inserted into another layout before geometry management will work.

Definition at line 127 of file qlayout.cpp.

Referenced by QLayoutPrivate::createSpacerItem(), QBoxLayout::QBoxLayout(), and QGridLayout::QGridLayout().

128  : QObject(*new QLayoutPrivate, 0)
129 {
130 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QLayout()

QLayout::~QLayout ( )

Destroys the layout, deleting all child layouts.

Warning
This function is not part of the public interface.

Geometry management stops when a top-level layout is deleted.

The layout classes will probably be fatally confused if you delete a sublayout.

Definition at line 936 of file qlayout.cpp.

937 {
938  Q_D(QLayout);
939  /*
940  This function may be called during the QObject destructor,
941  when the parent no longer is a QWidget.
942  */
943  if (d->topLevel && parent() && parent()->isWidgetType() &&
944  ((QWidget*)parent())->layout() == this)
945  ((QWidget*)parent())->d_func()->layout = 0;
946 }
double d
Definition: qnumeric_p.h:62
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QLayout * layout()
Reimplemented Function

◆ QLayout() [3/3]

QLayout::QLayout ( QLayoutPrivate dd,
QLayout lay,
QWidget w 
)
protected
Warning
This function is not part of the public interface.

Definition at line 135 of file qlayout.cpp.

136  : QObject(dd, lay ? static_cast<QObject*>(lay) : static_cast<QObject*>(w))
137 {
138  Q_D(QLayout);
139  if (lay) {
140  lay->addItem(this);
141  } else if (w) {
142  if (w->layout()) {
143  qWarning("QLayout: Attempting to add QLayout \"%s\" to %s \"%s\", which"
144  " already has a layout",
146  w->objectName().toLocal8Bit().data());
147  setParent(0);
148  } else {
149  d->topLevel = true;
150  w->d_func()->layout = this;
151  QT_TRY {
152  invalidate();
153  } QT_CATCH(...) {
154  w->d_func()->layout = 0;
155  QT_RETHROW;
156  }
157  }
158  }
159 }
double d
Definition: qnumeric_p.h:62
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
virtual void addItem(QLayoutItem *)=0
Implemented in subclasses to add an item.
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
#define Q_D(Class)
Definition: qglobal.h:2482
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
#define QT_RETHROW
Definition: qglobal.h:1539
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
Q_CORE_EXPORT void qWarning(const char *,...)
#define QT_CATCH(A)
Definition: qglobal.h:1537
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString objectName() const
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
#define qPrintable(string)
Definition: qglobal.h:1750
#define QT_TRY
Definition: qglobal.h:1536
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

Functions

◆ activate()

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.

See also
update(), QWidget::updateGeometry()

Definition at line 1249 of file qlayout.cpp.

Referenced by QWidgetPrivate::activateChildLayoutsRecursively(), QMessageBoxPrivate::layoutMinimumWidth(), QWidget::setVisible(), QWidgetPrivate::show_recursive(), QComboBox::showPopup(), and QMessageBoxPrivate::updateSize().

1250 {
1251  Q_D(QLayout);
1252  if (!d->enabled || !parent())
1253  return false;
1254  if (!d->topLevel)
1255  return static_cast<QLayout*>(parent())->activate();
1256  if (d->activated)
1257  return false;
1258  QWidget *mw = static_cast<QWidget*>(parent());
1259  if (mw == 0) {
1260  qWarning("QLayout::activate: %s \"%s\" does not have a main widget",
1261  QObject::metaObject()->className(), QObject::objectName().toLocal8Bit().data());
1262  return false;
1263  }
1265 
1266  QWidgetPrivate *md = mw->d_func();
1267  uint explMin = md->extra ? md->extra->explicitMinSize : 0;
1268  uint explMax = md->extra ? md->extra->explicitMaxSize : 0;
1269 
1270  switch (d->constraint) {
1271  case SetFixedSize:
1272  // will trigger resize
1273  mw->setFixedSize(totalSizeHint());
1274  break;
1275  case SetMinimumSize:
1277  break;
1278  case SetMaximumSize:
1280  break;
1281  case SetMinAndMaxSize:
1284  break;
1285  case SetDefaultConstraint: {
1286  bool widthSet = explMin & Qt::Horizontal;
1287  bool heightSet = explMin & Qt::Vertical;
1288  if (mw->isWindow()) {
1289  QSize ms = totalMinimumSize();
1290  if (widthSet)
1291  ms.setWidth(mw->minimumSize().width());
1292  if (heightSet)
1293  ms.setHeight(mw->minimumSize().height());
1294  if ((!heightSet || !widthSet) && hasHeightForWidth()) {
1295  int h = minimumHeightForWidth(ms.width());
1296  if (h > ms.height()) {
1297  if (!heightSet)
1298  ms.setHeight(0);
1299  if (!widthSet)
1300  ms.setWidth(0);
1301  }
1302  }
1303  mw->setMinimumSize(ms);
1304  } else if (!widthSet || !heightSet) {
1305  QSize ms = mw->minimumSize();
1306  if (!widthSet)
1307  ms.setWidth(0);
1308  if (!heightSet)
1309  ms.setHeight(0);
1310  mw->setMinimumSize(ms);
1311  }
1312  break;
1313  }
1314  case SetNoConstraint:
1315  break;
1316  }
1317 
1318  d->doResize(mw->size());
1319 
1320  if (md->extra) {
1321  md->extra->explicitMinSize = explMin;
1322  md->extra->explicitMaxSize = explMax;
1323  }
1324  // ideally only if sizeHint() or sizePolicy() has changed
1325  mw->updateGeometry();
1326  return true;
1327 }
double d
Definition: qnumeric_p.h:62
QSize minimumSize
the widget&#39;s minimum size
Definition: qwidget.h:172
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setMaximumSize(const QSize &)
Definition: qwidget.h:972
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition: qlayout.cpp:1249
virtual int minimumHeightForWidth(int) const
Returns the minimum height this widget needs for the given width, w.
void setMinimumSize(const QSize &)
Definition: qwidget.h:969
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
virtual bool hasHeightForWidth() const
Returns true if this layout&#39;s preferred height depends on its width; otherwise returns false...
#define Q_D(Class)
Definition: qglobal.h:2482
const char * className
Definition: qwizard.cpp:137
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
int width() const
Returns the width.
Definition: qsize.h:126
QSize totalMaximumSize() const
Also takes contentsMargins and menu bar into account.
Definition: qlayout.cpp:902
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
static void activateRecursiveHelper(QLayoutItem *item)
Definition: qlayout.cpp:1203
uint explicitMaxSize
Definition: qwidget_p.h:274
void setFixedSize(const QSize &)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing o...
Definition: qwidget.cpp:4284
QSize totalSizeHint() const
Also takes contentsMargins and menu bar into account.
Definition: qlayout.cpp:874
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QString objectName() const
int height() const
Returns the height.
Definition: qsize.h:129
QWExtra * extra
Definition: qwidget_p.h:700
QSize totalMinimumSize() const
Also takes contentsMargins and menu bar into account.
Definition: qlayout.cpp:848
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
uint explicitMinSize
Definition: qwidget_p.h:273

◆ activateRecursiveHelper()

void QLayout::activateRecursiveHelper ( QLayoutItem item)
staticprivate

Definition at line 1203 of file qlayout.cpp.

1204 {
1205  item->invalidate();
1206  QLayout *layout = item->layout();
1207  if (layout) {
1208  QLayoutItem *child;
1209  int i=0;
1210  while ((child = layout->itemAt(i++)))
1211  activateRecursiveHelper(child);
1212  layout->d_func()->activated = true;
1213  }
1214 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
virtual void invalidate()
Invalidates any cached information in this layout item.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
static void activateRecursiveHelper(QLayoutItem *item)
Definition: qlayout.cpp:1203
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
QLayout * layout()
Reimplemented Function

◆ addChildLayout()

void QLayout::addChildLayout ( QLayout l)
protected

This function is called from addLayout() or insertLayout() functions in subclasses to add layout l 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
QBoxLayout::addLayout(), QBoxLayout::insertLayout(), QGridLayout::addLayout()

Definition at line 969 of file qlayout.cpp.

970 {
971  if (l->parent()) {
972  qWarning("QLayout::addChildLayout: layout \"%s\" already has a parent",
973  l->objectName().toLocal8Bit().data());
974  return;
975  }
976  l->setParent(this);
977 
978  if (QWidget *mw = parentWidget()) {
979  l->d_func()->reparentChildWidgets(mw);
980  }
981 
982 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QString objectName() const

◆ addChildWidget()

void QLayout::addChildWidget ( QWidget w)
protected

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 give a warning and remove w from that layout. This function must therefore be called before adding w to the layout's data structure.

Definition at line 1045 of file qlayout.cpp.

Referenced by QGridLayout::addWidget(), QStackedLayout::insertWidget(), QBoxLayout::insertWidget(), QMainWindowLayout::setCentralWidget(), QMainWindowLayout::setStatusBar(), and QDockWidgetLayout::setWidgetForRole().

1046 {
1047  QWidget *mw = parentWidget();
1048  QWidget *pw = w->parentWidget();
1049 
1050  //Qt::WA_LaidOut is never reset. It only means that the widget at some point has
1051  //been in a layout.
1052  if (pw && w->testAttribute(Qt::WA_LaidOut)) {
1053  QLayout *l = pw->layout();
1054  if (l && removeWidgetRecursively(l, w)) {
1055 #ifdef QT_DEBUG
1056  if (layoutDebug())
1057  qWarning("QLayout::addChildWidget: %s \"%s\" is already in a layout; moved to new layout",
1058  w->metaObject()->className(), w->objectName().toLocal8Bit().data());
1059 #endif
1060  }
1061  }
1062  if (pw && mw && pw != mw) {
1063 #ifdef QT_DEBUG
1064  if (layoutDebug())
1065  qWarning("QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent",
1066  w->metaObject()->className(), w->objectName().toLocal8Bit().data());
1067 #endif
1068  pw = 0;
1069  }
1070  bool needShow = mw && mw->isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
1071  if (!pw && mw)
1072  w->setParent(mw);
1074  if (needShow)
1075  QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later
1076 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
bool isVisible() const
Definition: qwidget.h:1005
static bool layoutDebug()
Definition: qlayout.cpp:995
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString objectName() const
QFactoryLoader * l
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
static bool removeWidgetRecursively(QLayoutItem *li, QWidget *w)
Definition: qlayout.cpp:680
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ addItem()

void QLayout::addItem ( QLayoutItem item)
pure virtual

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
addWidget(), QBoxLayout::addLayout(), QGridLayout::addLayout()

Implemented in QMainWindowLayout, QGridLayout, QDockWidgetLayout, QFormLayout, QStackedLayout, QBoxLayout, and QToolBarLayout.

Referenced by QGridLayout::addWidget(), QLayoutPrivate::createSpacerItem(), QHBoxLayout::QHBoxLayout(), QLayout(), and QVBoxLayout::QVBoxLayout().

◆ addWidget()

void QLayout::addWidget ( QWidget w)

Adds widget w to this layout in a manner specific to the layout.

This function uses addItem().

Definition at line 319 of file qlayout.cpp.

Referenced by QGridLayout::addWidget(), QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(), QWizardHeader::QWizardHeader(), QToolBoxPrivate::relayout(), QMdiSubWindowPrivate::setSizeGrip(), QMdiSubWindow::setWidget(), and QMenuBarPrivate::updateCornerWidgetToolBar().

320 {
321  addChildWidget(w);
323 }
virtual void addItem(QLayoutItem *)=0
Implemented in subclasses to add an item.
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
Definition: qlayout.cpp:190
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
Definition: qlayout.cpp:1045

◆ adoptLayout()

bool QLayout::adoptLayout ( QLayout layout)
protected
Warning
This function is not part of the public interface.

Definition at line 987 of file qlayout.cpp.

Referenced by QGridLayout::addLayout(), and QBoxLayout::insertLayout().

988 {
989  const bool ok = !layout->parent();
990  addChildLayout(layout);
991  return ok;
992 }
void addChildLayout(QLayout *l)
This function is called from addLayout() or insertLayout() functions in subclasses to add layout l as...
Definition: qlayout.cpp:969
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ alignmentRect()

QRect QLayout::alignmentRect ( const QRect r) const
protected

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.

Definition at line 1459 of file qlayout.cpp.

Referenced by QBoxLayout::setGeometry(), and QGridLayout::setGeometry().

1460 {
1461  QSize s = sizeHint();
1462  Qt::Alignment a = alignment();
1463 
1464  /*
1465  This is a hack to obtain the real maximum size, not
1466  QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX), the value consistently
1467  returned by QLayoutItems that have an alignment.
1468  */
1469  QLayout *that = const_cast<QLayout *>(this);
1470  that->setAlignment(0);
1471  QSize ms = that->maximumSize();
1472  that->setAlignment(a);
1473 
1474  if ((expandingDirections() & Qt::Horizontal) ||
1475  !(a & Qt::AlignHorizontal_Mask)) {
1476  s.setWidth(qMin(r.width(), ms.width()));
1477  }
1478  if ((expandingDirections() & Qt::Vertical) ||
1479  !(a & Qt::AlignVertical_Mask)) {
1480  s.setHeight(qMin(r.height(), ms.height()));
1481  } else if (hasHeightForWidth()) {
1482  int hfw = heightForWidth(s.width());
1483  if (hfw < s.height())
1484  s.setHeight(qMin(hfw, ms.height()));
1485  }
1486 
1487  s = s.boundedTo(r.size());
1488  int x = r.x();
1489  int y = r.y();
1490 
1491  if (a & Qt::AlignBottom)
1492  y += (r.height() - s.height());
1493  else if (!(a & Qt::AlignTop))
1494  y += (r.height() - s.height()) / 2;
1495 
1498  if (a & Qt::AlignRight)
1499  x += (r.width() - s.width());
1500  else if (!(a & Qt::AlignLeft))
1501  x += (r.width() - s.width()) / 2;
1502 
1503  return QRect(x, y, s.width(), s.height());
1504 }
static Qt::LayoutDirection layoutDirection()
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
long ASN1_INTEGER_get ASN1_INTEGER * a
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
virtual bool hasHeightForWidth() const
Returns true if this layout&#39;s preferred height depends on its width; otherwise returns false...
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
Qt::Orientations expandingDirections() const
Returns whether this layout can make use of more space than sizeHint().
Definition: qlayout.cpp:1198
QSize maximumSize() const
Returns the maximum size of this layout.
Definition: qlayout.cpp:1181
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
int width() const
Returns the width.
Definition: qsize.h:126
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
Qt::LayoutDirection layoutDirection
the layout direction for this widget
Definition: qwidget.h:216
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
Definition: qstyle.cpp:2149
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition: qlayoutitem.h:85
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width w.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool setAlignment(QWidget *w, Qt::Alignment alignment)
Sets the alignment for widget w to alignment and returns true if w is found in this layout (not inclu...
Definition: qlayout.cpp:332

◆ childEvent()

void QLayout::childEvent ( QChildEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 793 of file qlayout.cpp.

794 {
795  Q_D(QLayout);
796  if (!d->enabled)
797  return;
798 
799  if (e->type() == QEvent::ChildRemoved) {
800  QChildEvent *c = (QChildEvent*)e;
801  int i = 0;
802 
803  QLayoutItem *item;
804  while ((item = itemAt(i))) {
805  if (item == static_cast<QLayout*>(c->child())) {
806  takeAt(i);
807  invalidate();
808  break;
809  } else {
810  ++i;
811  }
812  }
813  }
814 }
double d
Definition: qnumeric_p.h:62
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
unsigned char c[8]
Definition: qnumeric_p.h:62
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QLayoutItem * takeAt(int index)=0
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:353
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
QObject * child() const
Returns the child object that was added or removed.
Definition: qcoreevent.h:358

◆ closestAcceptableSize()

QSize QLayout::closestAcceptableSize ( const QWidget w,
const QSize s 
)
static

Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size.

Definition at line 1586 of file qlayout.cpp.

Referenced by make_win_eventUPP(), QSizeGrip::mouseMoveEvent(), and QtWndProc().

1587 {
1588  QSize result = size.boundedTo(qSmartMaxSize(widget));
1589  result = result.expandedTo(qSmartMinSize(widget));
1590  QLayout *l = widget->layout();
1591  if (l && l->hasHeightForWidth() && result.height() < l->minimumHeightForWidth(result.width()) ) {
1592  QSize current = widget->size();
1593  int currentHfw = l->minimumHeightForWidth(current.width());
1594  int newHfw = l->minimumHeightForWidth(result.width());
1595  if (current.height() < currentHfw || currentHfw == newHfw) {
1596  //handle the constant hfw case and the vertical-only case, as well as the
1597  // current-size-is-not-correct case
1598  result.setHeight(newHfw);
1599  } else {
1600  // binary search; assume hfw is decreasing ###
1601 
1602  int maxw = qMax(widget->width(),result.width());
1603  int maxh = qMax(widget->height(), result.height());
1604  int minw = qMin(widget->width(),result.width());
1605  int minh = qMin(widget->height(), result.height());
1606 
1607  int minhfw = l->minimumHeightForWidth(minw);
1608  int maxhfw = l->minimumHeightForWidth(maxw);
1609  while (minw < maxw) {
1610  if (minhfw > maxh) { //assume decreasing
1611  minw = maxw - (maxw-minw)/2;
1612  minhfw = l->minimumHeightForWidth(minw);
1613  } else if (maxhfw < minh ) { //assume decreasing
1614  maxw = minw + (maxw-minw)/2;
1615  maxhfw = l->minimumHeightForWidth(maxw);
1616  } else {
1617  break;
1618  }
1619  }
1620  result = result.expandedTo(QSize(minw, minhfw));
1621  }
1622  }
1623  return result;
1624 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
Q_GUI_EXPORT QSize qSmartMaxSize(const QSize &sizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy, Qt::Alignment align)
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
virtual int minimumHeightForWidth(int) const
Returns the minimum height this widget needs for the given width, w.
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
virtual bool hasHeightForWidth() const
Returns true if this layout&#39;s preferred height depends on its width; otherwise returns false...
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int width() const
Returns the width.
Definition: qsize.h:126
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
int height() const
Returns the height.
Definition: qsize.h:129
QFactoryLoader * l
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ contentsMargins()

QMargins QLayout::contentsMargins ( ) const

Returns the margins used around the layout.

Since
4.6

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also
setContentsMargins()

Definition at line 573 of file qlayout.cpp.

574 {
575  int left, top, right, bottom;
576  getContentsMargins(&left, &top, &right, &bottom);
577  return QMargins(left, top, right, bottom);
578 }
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Definition: qlayout.cpp:551
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:53
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ contentsRect()

QRect QLayout::contentsRect ( ) const

Returns the layout's geometry() rectangle, but taking into account the contents margins.

Since
4.3
See also
setContentsMargins(), getContentsMargins()

Definition at line 591 of file qlayout.cpp.

592 {
593  Q_D(const QLayout);
594  int left, top, right, bottom;
595  getContentsMargins(&left, &top, &right, &bottom);
596  return d->rect.adjusted(+left, +top, -right, -bottom);
597 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Definition: qlayout.cpp:551
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ count()

int * QLayout::count ( ) const
pure virtual

◆ expandingDirections()

Qt::Orientations QLayout::expandingDirections ( ) const
virtual

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
sizeHint()

Implements QLayoutItem.

Reimplemented in QToolBarLayout.

Definition at line 1198 of file qlayout.cpp.

Referenced by QWidgetPrivate::adjustedSize().

1199 {
1200  return Qt::Horizontal | Qt::Vertical;
1201 }

◆ geometry()

QRect QLayout::geometry ( ) const
virtual

Reimplemented Function

Implements QLayoutItem.

Definition at line 664 of file qlayout.cpp.

Referenced by QDockWidgetPrivate::endDrag(), QBoxLayout::setGeometry(), QGridLayout::setGeometry(), QFormLayout::setGeometry(), QDockWidgetLayout::setGeometry(), and QStackedLayout::setStackingMode().

665 {
666  Q_D(const QLayout);
667  return d->rect;
668 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90

◆ getContentsMargins()

void QLayout::getContentsMargins ( int *  left,
int *  top,
int *  right,
int *  bottom 
) const
Since
4.3

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
setContentsMargins(), QStyle::pixelMetric(), {QStyle::}{PM_LayoutLeftMargin}, {QStyle::}{PM_LayoutTopMargin}, {QStyle::}{PM_LayoutRightMargin}, {QStyle::}{PM_LayoutBottomMargin}

Definition at line 551 of file qlayout.cpp.

Referenced by QFormLayout::heightForWidth(), QFontDialogPrivate::init(), and QFormLayout::setGeometry().

552 {
553  Q_D(const QLayout);
554  d->getMargin(left, d->userLeftMargin, QStyle::PM_LayoutLeftMargin);
555  d->getMargin(top, d->userTopMargin, QStyle::PM_LayoutTopMargin);
556  d->getMargin(right, d->userRightMargin, QStyle::PM_LayoutRightMargin);
557  d->getMargin(bottom, d->userBottomMargin, QStyle::PM_LayoutBottomMargin);
558 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ indexOf()

int QLayout::indexOf ( QWidget widget) const
virtual

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()

Reimplemented in QToolBarLayout.

Definition at line 1378 of file qlayout.cpp.

Referenced by QFormLayout::getWidgetPosition(), QToolBarLayout::indexOf(), QGridLayout::minimumHeightForWidth(), QStackedLayout::setCurrentWidget(), and QMdiSubWindowPrivate::setSizeGrip().

1379 {
1380  int i = 0;
1381  QLayoutItem *item = itemAt(i);
1382  while (item) {
1383  if (item->widget() == widget)
1384  return i;
1385  ++i;
1386  item = itemAt(i);
1387  }
1388  return -1;
1389 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.

◆ invalidate()

void QLayout::invalidate ( )
virtual

Reimplemented Function

Reimplemented from QLayoutItem.

Reimplemented in QMainWindowLayout, and QToolBarLayout.

Definition at line 673 of file qlayout.cpp.

Referenced by QStackedLayout::insertWidget(), QToolBarLayout::invalidate(), QBoxLayout::invalidate(), QGridLayout::invalidate(), QFormLayout::invalidate(), QMainWindowLayout::invalidate(), QLayout(), removeWidgetRecursively(), QWidget::setLayout(), QDockWidgetLayout::setVerticalTitleBar(), QWidget::setVisible(), QDockWidgetLayout::setWidgetForRole(), QDockWidgetLayout::takeAt(), QDockWidgetPrivate::updateButtons(), and QWidgetPrivate::updateGeometry_helper().

674 {
675  Q_D(QLayout);
676  d->rect = QRect();
677  update();
678 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the layout for parentWidget().
Definition: qlayout.cpp:1225
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ isEmpty()

bool QLayout::isEmpty ( ) const
virtual

Reimplemented Function

Implements QLayoutItem.

Reimplemented in QToolBarLayout.

Definition at line 639 of file qlayout.cpp.

640 {
641  int i = 0;
642  QLayoutItem *item = itemAt(i);
643  while (item) {
644  if (!item->isEmpty())
645  return false;
646  ++i;
647  item = itemAt(i);
648  }
649  return true;
650 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
virtual bool isEmpty() const =0
Implemented in subclasses to return whether this item is empty, i.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64

◆ isEnabled()

bool QLayout::isEnabled ( ) const

Returns true if the layout is enabled; otherwise returns false.

See also
setEnabled()

Definition at line 1574 of file qlayout.cpp.

1575 {
1576  Q_D(const QLayout);
1577  return d->enabled;
1578 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90

◆ itemAt()

QLayoutItem * QLayout::itemAt ( int  index) const
pure virtual

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.

static void paintLayout(QPainter *painter, QLayoutItem *item)
{
QLayout *layout = item->layout();
if (layout) {
for (int i = 0; i < layout->count(); ++i)
paintLayout(painter, layout->itemAt(i));
}
painter->drawRect(item->geometry());
}
void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if (layout())
paintLayout(&painter, layout());
}
See also
count(), takeAt()

Implemented in QMainWindowLayout, QDockWidgetLayout, QFormLayout, QGridLayout, QBoxLayout, QStackedLayout, and QToolBarLayout.

Referenced by activateRecursiveHelper(), QGridLayout::addWidget(), changeSpacerSize(), QLayoutItem::controlTypes(), removeWidgetRecursively(), QAbstractScrollAreaScrollBarContainer::scrollBarLayoutIndex(), QToolBar::setIconSize(), QDeclarativeView::setRootObject(), and QAbstractScrollAreaScrollBarContainer::widgets().

◆ layout()

QLayout * QLayout::layout ( )
virtual

Reimplemented Function

Reimplemented from QLayoutItem.

Definition at line 360 of file qlayoutitem.cpp.

Referenced by QFormLayoutItem::layout(), QWidget::layout(), QToolBarLayout::setExpanded(), QBoxLayout::setStretchFactor(), and QMenuBarPrivate::updateCornerWidgetToolBar().

361 {
362  return this;
363 }

◆ margin()

int QLayout::margin ( ) const

◆ maximumSize()

QSize QLayout::maximumSize ( ) const
virtual

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.

Implements QLayoutItem.

Reimplemented in QDockWidgetLayout.

Definition at line 1181 of file qlayout.cpp.

Referenced by alignmentRect(), and QToolBarLayout::layoutActions().

1182 {
1184 }
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56

◆ menuBar()

QWidget * QLayout::menuBar ( ) const

Returns the menu bar set for this layout, or 0 if no menu bar is set.

Definition at line 1149 of file qlayout.cpp.

Referenced by QMainWindow::menuBar(), QMainWindow::menuWidget(), and QMainWindow::setMenuBar().

1150 {
1151  Q_D(const QLayout);
1152  return d->menubar;
1153 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90

◆ minimumSize()

QSize QLayout::minimumSize ( ) const
virtual

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.

Implements QLayoutItem.

Reimplemented in QMainWindowLayout, QDockWidgetLayout, QToolBarLayout, and QStackedLayout.

Definition at line 1166 of file qlayout.cpp.

Referenced by QMdiSubWindow::minimumSizeHint().

1167 {
1168  return QSize(0, 0);
1169 }
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ parentWidget()

QWidget * QLayout::parentWidget ( ) const

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()

Definition at line 616 of file qlayout.cpp.

Referenced by QToolBarLayout::createItem(), QToolBarLayout::expandedSize(), QToolBarLayout::expandingDirections(), QMainWindowLayout::hover(), QToolBarLayout::layoutActions(), QDockWidgetLayout::maximumSize(), QDockWidgetLayout::minimumSize(), QDockWidgetLayout::minimumTitleWidth(), QToolBarLayout::movable(), QDockWidgetLayout::nativeWindowDeco(), parentWidget(), QMainWindowLayout::restoreState(), QStackedLayout::setCurrentIndex(), QToolBarLayout::setExpanded(), QToolBarLayout::setGeometry(), QBoxLayout::setGeometry(), QDockWidgetLayout::setGeometry(), QDockWidgetLayout::setVerticalTitleBar(), QDockWidgetLayout::sizeFromContent(), QDockWidgetLayout::sizeHint(), QMainWindowLayout::timerEvent(), QDockWidgetLayout::titleHeight(), QToolBarLayout::updateGeomArray(), and QToolBarLayout::updateMarginAndSpacing().

617 {
618  Q_D(const QLayout);
619  if (!d->topLevel) {
620  if (parent()) {
621  QLayout *parentLayout = qobject_cast<QLayout*>(parent());
622  if (!parentLayout) {
623  qWarning("QLayout::parentWidget: A layout can only have another layout as a parent.");
624  return 0;
625  }
626  return parentLayout->parentWidget();
627  } else {
628  return 0;
629  }
630  } else {
631  Q_ASSERT(parent() && parent()->isWidgetType());
632  return static_cast<QWidget *>(parent());
633  }
634 }
double d
Definition: qnumeric_p.h:62
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
Q_CORE_EXPORT void qWarning(const char *,...)
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ removeItem()

void QLayout::removeItem ( QLayoutItem item)

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
removeWidget(), addItem()

Definition at line 1539 of file qlayout.cpp.

1540 {
1541  int i = 0;
1542  QLayoutItem *child;
1543  while ((child = itemAt(i))) {
1544  if (child == item) {
1545  takeAt(i);
1546  invalidate();
1547  } else {
1548  ++i;
1549  }
1550  }
1551 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
virtual QLayoutItem * takeAt(int index)=0
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64

◆ removeWidget()

void QLayout::removeWidget ( QWidget widget)

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.

Note: The ownership of widget remains the same as when it was added.

See also
removeItem(), QWidget::setGeometry(), addWidget()

Definition at line 1516 of file qlayout.cpp.

Referenced by QToolBoxPrivate::_q_widgetDestroyed(), QMdiSubWindowPrivate::removeBaseWidget(), QAbstractScrollAreaPrivate::replaceScrollBar(), QMessageBox::setInformativeText(), QInputDialogPrivate::setInputWidget(), and QDockWidgetLayout::setWidgetForRole().

1517 {
1518  int i = 0;
1519  QLayoutItem *child;
1520  while ((child = itemAt(i))) {
1521  if (child->widget() == widget) {
1522  delete takeAt(i);
1523  invalidate();
1524  } else {
1525  ++i;
1526  }
1527  }
1528 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
virtual QLayoutItem * takeAt(int index)=0
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.

◆ setAlignment() [1/2]

bool QLayout::setAlignment ( QWidget w,
Qt::Alignment  alignment 
)

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.

Definition at line 332 of file qlayout.cpp.

Referenced by alignmentRect(), QPrintPreviewDialogPrivate::init(), and QMdiSubWindowPrivate::setSizeGrip().

333 {
334  int i = 0;
335  QLayoutItem *item = itemAt(i);
336  while (item) {
337  if (item->widget() == w) {
338  item->setAlignment(alignment);
339  invalidate();
340  return true;
341  }
342  ++i;
343  item = itemAt(i);
344  }
345  return false;
346 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
void setAlignment(Qt::Alignment a)
Sets the alignment of this item to alignment.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition: qlayoutitem.h:85
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.

◆ setAlignment() [2/2]

bool QLayout::setAlignment ( QLayout l,
Qt::Alignment  alignment 
)

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.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 358 of file qlayout.cpp.

359 {
360  int i = 0;
361  QLayoutItem *item = itemAt(i);
362  while (item) {
363  if (item->layout() == l) {
364  item->setAlignment(alignment);
365  invalidate();
366  return true;
367  }
368  ++i;
369  item = itemAt(i);
370  }
371  return false;
372 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
void setAlignment(Qt::Alignment a)
Sets the alignment of this item to alignment.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
QFactoryLoader * l
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition: qlayoutitem.h:85

◆ setContentsMargins() [1/2]

void QLayout::setContentsMargins ( int  left,
int  top,
int  right,
int  bottom 
)

Sets the left, top, right, and bottom margins to use around the layout.

Since
4.3

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also
getContentsMargins(), QStyle::pixelMetric(), {QStyle::}{PM_LayoutLeftMargin}, {QStyle::}{PM_LayoutTopMargin}, {QStyle::}{PM_LayoutRightMargin}, {QStyle::}{PM_LayoutBottomMargin}

Definition at line 502 of file qlayout.cpp.

Referenced by QMainWindowPrivate::init(), QPrintPreviewDialogPrivate::init(), QPrintPreviewWidgetPrivate::init(), and QDialogButtonBoxPrivate::initLayout().

503 {
504  Q_D(QLayout);
505 
506  if (d->userLeftMargin == left && d->userTopMargin == top &&
507  d->userRightMargin == right && d->userBottomMargin == bottom)
508  return;
509 
510  d->userLeftMargin = left;
511  d->userTopMargin = top;
512  d->userRightMargin = right;
513  d->userBottomMargin = bottom;
514  invalidate();
515 }
double d
Definition: qnumeric_p.h:62
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ setContentsMargins() [2/2]

void QLayout::setContentsMargins ( const QMargins margins)

Sets the margins to use around the layout.

Since
4.6

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also
contentsMargins()

Definition at line 530 of file qlayout.cpp.

531 {
532  setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom());
533 }
int top() const
Returns the top margin.
Definition: qmargins.h:99
void setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
Definition: qlayout.cpp:502
int left() const
Returns the left margin.
Definition: qmargins.h:96
int bottom() const
Returns the bottom margin.
Definition: qmargins.h:105
int right() const
Returns the right margin.
Definition: qmargins.h:102

◆ setEnabled()

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.

See also
isEnabled()

Definition at line 1563 of file qlayout.cpp.

Referenced by QDialog::showExtension().

1564 {
1565  Q_D(QLayout);
1566  d->enabled = enable;
1567 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90

◆ setGeometry()

void QLayout::setGeometry ( const QRect r)
virtual

Reimplemented Function

Implements QLayoutItem.

Reimplemented in QMainWindowLayout, QDockWidgetLayout, QFormLayout, QGridLayout, QBoxLayout, QStackedLayout, and QToolBarLayout.

Definition at line 655 of file qlayout.cpp.

Referenced by QGridLayout::addWidget(), QToolBarLayout::setGeometry(), QBoxLayout::setGeometry(), QGridLayout::setGeometry(), QFormLayout::setGeometry(), and QMainWindowLayout::setGeometry().

656 {
657  Q_D(QLayout);
658  d->rect = r;
659 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90

◆ setMargin()

void QLayout::setMargin ( int  margin)

Definition at line 464 of file qlayout.cpp.

Referenced by QCalendarWidgetPrivate::createNavigationBar(), QWorkspaceChild::iconWidget(), QPrintPreviewDialogPrivate::init(), QMessageBoxPrivate::init(), QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(), QBalloonTip::QBalloonTip(), QBoxLayout::QBoxLayout(), QCalendarWidget::QCalendarWidget(), QColorShower::QColorShower(), QComboBoxPrivateContainer::QComboBoxPrivateContainer(), QGridLayout::QGridLayout(), QHBoxLayout::QHBoxLayout(), QMdiSubWindow::QMdiSubWindow(), QMessageBoxDetailsText::QMessageBoxDetailsText(), QScriptBreakpointsWidget::QScriptBreakpointsWidget(), QScriptDebuggerCodeFinderWidget::QScriptDebuggerCodeFinderWidget(), QScriptDebuggerCodeView::QScriptDebuggerCodeView(), QScriptDebuggerCodeWidget::QScriptDebuggerCodeWidget(), QScriptDebuggerConsoleWidget::QScriptDebuggerConsoleWidget(), QScriptDebuggerLocalsWidget::QScriptDebuggerLocalsWidget(), QScriptDebuggerScriptsWidget::QScriptDebuggerScriptsWidget(), QScriptDebuggerStackWidget::QScriptDebuggerStackWidget(), QScriptDebugOutputWidget::QScriptDebugOutputWidget(), QScriptErrorLogWidget::QScriptErrorLogWidget(), QScriptNewBreakpointWidget::QScriptNewBreakpointWidget(), QVBoxLayout::QVBoxLayout(), QWizardHeader::QWizardHeader(), QToolBoxPrivate::relayout(), QCalendarPopup::setCalendarWidget(), QScriptEngineDebugger::standardWindow(), QCoreFuriCuri::timerEvent(), and QToolBarLayout::updateMarginAndSpacing().

465 {
467 }
void setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
Definition: qlayout.cpp:502
int margin() const

◆ setMenuBar()

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.

Definition at line 1131 of file qlayout.cpp.

Referenced by QMainWindow::setMenuBar().

1132 {
1133  Q_D(QLayout);
1134 
1135 #ifdef Q_OS_WINCE_WM
1136  if (widget && widget->size().height() > 0)
1137 #else
1138  if (widget)
1139 #endif
1140  addChildWidget(widget);
1141  d->menubar = widget;
1142 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
Definition: qlayout.cpp:1045
int height() const
Returns the height.
Definition: qsize.h:129
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.

◆ setSizeConstraint()

void QLayout::setSizeConstraint ( SizeConstraint  constraint)

Definition at line 1435 of file qlayout.cpp.

Referenced by QInputDialogPrivate::ensureLayout(), QColorDialogPrivate::init(), QDockWidgetPrivate::init(), QMessageBoxPrivate::init(), and QBalloonTip::QBalloonTip().

1436 {
1437  Q_D(QLayout);
1438  if (constraint == d->constraint)
1439  return;
1440 
1441  d->constraint = constraint;
1442  invalidate();
1443 }
double d
Definition: qnumeric_p.h:62
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
#define Q_D(Class)
Definition: qglobal.h:2482
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90

◆ setSpacing()

void QLayout::setSpacing ( int  spacing)

Definition at line 469 of file qlayout.cpp.

Referenced by QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(), QWizardHeader::QWizardHeader(), and QToolBarLayout::updateMarginAndSpacing().

470 {
471  if (QBoxLayout* boxlayout = qobject_cast<QBoxLayout*>(this)) {
472  boxlayout->setSpacing(spacing);
473  } else if (QGridLayout* gridlayout = qobject_cast<QGridLayout*>(this)) {
474  gridlayout->setSpacing(spacing);
475  } else if (QFormLayout* formlayout = qobject_cast<QFormLayout*>(this)) {
476  formlayout->setSpacing(spacing);
477  } else {
478  Q_D(QLayout);
479  d->insideSpacing = spacing;
480  invalidate();
481  }
482 }
double d
Definition: qnumeric_p.h:62
The QBoxLayout class lines up child widgets horizontally or vertically.
Definition: qboxlayout.h:60
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
#define Q_D(Class)
Definition: qglobal.h:2482
int spacing() const
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:60
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55

◆ sizeConstraint()

SizeConstraint QLayout::sizeConstraint ( ) const

Referenced by setSizeConstraint().

◆ spacing()

int QLayout::spacing ( ) const

◆ takeAt()

QLayoutItem * QLayout::takeAt ( int  index)
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 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:

QLayoutItem *child;
while ((child = layout->takeAt(0)) != 0) {
...
delete child;
}
See also
itemAt(), count()

Implemented in QMainWindowLayout, QDockWidgetLayout, QFormLayout, QGridLayout, QBoxLayout, QStackedLayout, and QToolBarLayout.

Referenced by QGridLayout::addWidget(), removeWidgetRecursively(), and QMenuBarPrivate::updateCornerWidgetToolBar().

◆ totalHeightForWidth()

int QLayout::totalHeightForWidth ( int  w) const

Also takes contentsMargins and menu bar into account.

Warning
This function is not part of the public interface.

Definition at line 823 of file qlayout.cpp.

Referenced by QWidgetPrivate::adjustedSize(), QWidget::heightForWidth(), and QMessageBoxPrivate::updateSize().

824 {
825  Q_D(const QLayout);
826  int side=0, top=0;
827  if (d->topLevel) {
829  parent->ensurePolished();
830  QWidgetPrivate *wd = parent->d_func();
831  side += wd->leftmargin + wd->rightmargin;
832  top += wd->topmargin + wd->bottommargin;
833  }
834  int h = heightForWidth(w - side) + top;
835 #ifndef QT_NO_MENUBAR
836  h += menuBarHeightForWidth(d->menubar, w);
837 #endif
838  return h;
839 }
double d
Definition: qnumeric_p.h:62
short rightmargin
Definition: qwidget_p.h:746
short topmargin
Definition: qwidget_p.h:745
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static int menuBarHeightForWidth(QWidget *menubar, int w)
Definition: qlayout.cpp:58
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
short leftmargin
Definition: qwidget_p.h:744
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
short bottommargin
Definition: qwidget_p.h:747
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width w.

◆ totalMaximumSize()

QSize QLayout::totalMaximumSize ( ) const

Also takes contentsMargins and menu bar into account.

Warning
This function is not part of the public interface.

Definition at line 902 of file qlayout.cpp.

903 {
904  Q_D(const QLayout);
905  int side=0, top=0;
906  if (d->topLevel) {
907  QWidget *pw = parentWidget();
908  pw->ensurePolished();
909  QWidgetPrivate *wd = pw->d_func();
910  side += wd->leftmargin + wd->rightmargin;
911  top += wd->topmargin + wd->bottommargin;
912  }
913 
914  QSize s = maximumSize();
915 #ifndef QT_NO_MENUBAR
916  top += menuBarHeightForWidth(d->menubar, s.width());
917 #endif
918 
919  if (d->topLevel)
920  s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX),
921  qMin(s.height() + top, QLAYOUTSIZE_MAX));
922  return s;
923 }
double d
Definition: qnumeric_p.h:62
short rightmargin
Definition: qwidget_p.h:746
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
short topmargin
Definition: qwidget_p.h:745
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static int menuBarHeightForWidth(QWidget *menubar, int w)
Definition: qlayout.cpp:58
#define Q_D(Class)
Definition: qglobal.h:2482
QSize maximumSize() const
Returns the maximum size of this layout.
Definition: qlayout.cpp:1181
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
int width() const
Returns the width.
Definition: qsize.h:126
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
short leftmargin
Definition: qwidget_p.h:744
int height() const
Returns the height.
Definition: qsize.h:129
short bottommargin
Definition: qwidget_p.h:747
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56

◆ totalMinimumSize()

QSize QLayout::totalMinimumSize ( ) const

Also takes contentsMargins and menu bar into account.

Warning
This function is not part of the public interface.

Definition at line 848 of file qlayout.cpp.

Referenced by QMessageBoxPrivate::layoutMinimumWidth(), QWizardHeader::setup(), and QMessageBoxPrivate::updateSize().

849 {
850  Q_D(const QLayout);
851  int side=0, top=0;
852  if (d->topLevel) {
853  QWidget *pw = parentWidget();
854  pw->ensurePolished();
855  QWidgetPrivate *wd = pw->d_func();
856  side += wd->leftmargin + wd->rightmargin;
857  top += wd->topmargin + wd->bottommargin;
858  }
859 
860  QSize s = minimumSize();
861 #ifndef QT_NO_MENUBAR
862  top += menuBarHeightForWidth(d->menubar, s.width() + side);
863 #endif
864  return s + QSize(side, top);
865 }
double d
Definition: qnumeric_p.h:62
short rightmargin
Definition: qwidget_p.h:746
short topmargin
Definition: qwidget_p.h:745
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static int menuBarHeightForWidth(QWidget *menubar, int w)
Definition: qlayout.cpp:58
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
int width() const
Returns the width.
Definition: qsize.h:126
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
short leftmargin
Definition: qwidget_p.h:744
QSize minimumSize() const
Returns the minimum size of this layout.
Definition: qlayout.cpp:1166
short bottommargin
Definition: qwidget_p.h:747
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ totalSizeHint()

QSize QLayout::totalSizeHint ( ) const

Also takes contentsMargins and menu bar into account.

Warning
This function is not part of the public interface.

Definition at line 874 of file qlayout.cpp.

875 {
876  Q_D(const QLayout);
877  int side=0, top=0;
878  if (d->topLevel) {
879  QWidget *pw = parentWidget();
880  pw->ensurePolished();
881  QWidgetPrivate *wd = pw->d_func();
882  side += wd->leftmargin + wd->rightmargin;
883  top += wd->topmargin + wd->bottommargin;
884  }
885 
886  QSize s = sizeHint();
887  if (hasHeightForWidth())
888  s.setHeight(heightForWidth(s.width() + side));
889 #ifndef QT_NO_MENUBAR
890  top += menuBarHeightForWidth(d->menubar, s.width());
891 #endif
892  return s + QSize(side, top);
893 }
double d
Definition: qnumeric_p.h:62
short rightmargin
Definition: qwidget_p.h:746
short topmargin
Definition: qwidget_p.h:745
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static int menuBarHeightForWidth(QWidget *menubar, int w)
Definition: qlayout.cpp:58
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
virtual bool hasHeightForWidth() const
Returns true if this layout&#39;s preferred height depends on its width; otherwise returns false...
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
int width() const
Returns the width.
Definition: qsize.h:126
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
short leftmargin
Definition: qwidget_p.h:744
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
short bottommargin
Definition: qwidget_p.h:747
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width w.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ update()

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.

See also
activate(), invalidate()

Definition at line 1225 of file qlayout.cpp.

Referenced by QMainWindowPrivate::adjustCursor(), and QX11EmbedWidget::resizeEvent().

1226 {
1227  QLayout *layout = this;
1228  while (layout && layout->d_func()->activated) {
1229  layout->d_func()->activated = false;
1230  if (layout->d_func()->topLevel) {
1231  Q_ASSERT(layout->parent()->isWidgetType());
1232  QWidget *mw = static_cast<QWidget*>(layout->parent());
1234  break;
1235  }
1236  layout = static_cast<QLayout*>(layout->parent());
1237  }
1238 }
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QLayout * layout()
Reimplemented Function
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ widgetEvent()

void QLayout::widgetEvent ( QEvent e)
protected

Performs child widget layout when the parent widget is resized.

Warning
This function is not part of the public interface. Also handles removal of widgets. e is the event

Definition at line 726 of file qlayout.cpp.

727 {
728  Q_D(QLayout);
729  if (!d->enabled)
730  return;
731 
732  switch (e->type()) {
733  case QEvent::Resize:
734  if (d->activated) {
735  QResizeEvent *r = (QResizeEvent *)e;
736  d->doResize(r->size());
737  } else {
738  activate();
739  }
740  break;
742  {
743  QChildEvent *c = (QChildEvent *)e;
744  if (c->child()->isWidgetType()) {
745  QWidget *w = (QWidget *)c->child();
746 #ifndef QT_NO_MENUBAR
747  if (w == d->menubar)
748  d->menubar = 0;
749 #endif
750  removeWidgetRecursively(this, w);
751  }
752  }
753  break;
754 #ifdef QT3_SUPPORT
755  case QEvent::ChildInserted:
756  if (d->topLevel && d->autoNewChild) {
757  QChildEvent *c = (QChildEvent *)e;
758  if (c->child()->isWidgetType()) {
759  QWidget *w = (QWidget *)c->child();
760  if (!w->isWindow()) {
761 #if !defined(QT_NO_MENUBAR) && !defined(QT_NO_TOOLBAR)
762  if (qobject_cast<QMenuBar*>(w) && !qobject_cast<QToolBar*>(w->parentWidget())) {
763  d->menubar = (QMenuBar *)w;
764  invalidate();
765  } else
766 #endif
767 #ifndef QT_NO_SIZEGRIP
768  if (qobject_cast<QSizeGrip*>(w) ) {
769  //SizeGrip is handled by the dialog itself.
770  } else
771 #endif
773  }
774  }
775  }
776  break;
777  case QEvent::LayoutHint:
778  d->activated = false;
779  // fall through
780 #endif
782  if (static_cast<QWidget *>(parent())->isVisible())
783  activate();
784  break;
785  default:
786  break;
787  }
788 }
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
unsigned char c[8]
Definition: qnumeric_p.h:62
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
virtual void addItem(QLayoutItem *)=0
Implemented in subclasses to add an item.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition: qlayout.cpp:1249
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:353
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
Definition: qlayout.cpp:190
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
const QSize & size() const
Returns the new size of the widget.
Definition: qevent.h:355
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static bool removeWidgetRecursively(QLayoutItem *li, QWidget *w)
Definition: qlayout.cpp:680
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
QObject * child() const
Returns the child object that was added or removed.
Definition: qcoreevent.h:358

Friends and Related Functions

◆ QApplicationPrivate

friend class QApplicationPrivate
friend

Definition at line 206 of file qlayout.h.

◆ QWidget

friend class QWidget
friend

Definition at line 207 of file qlayout.h.

Properties

◆ margin

int QLayout::margin
private

the width of the outside border of the layout

Use setContentsMargins() and getContentsMargins() instead.

See also
contentsRect(), spacing

Definition at line 96 of file qlayout.h.

Referenced by QCommonStyle::subElementRect().

◆ sizeConstraint

QLayout::SizeConstraint QLayout::sizeConstraint
private

the resize mode of the layout

The default mode is QLayout::SetDefaultConstraint {SetDefaultConstraint}.

Definition at line 98 of file qlayout.h.

◆ spacing

int QLayout::spacing
private

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 QGridLayout::setHorizontalSpacing() and QGridLayout::setVerticalSpacing(). In that case, spacing() returns -1.

See also
contentsRect(), getContentsMargins(), QStyle::layoutSpacing(), QStyle::pixelMetric()

Definition at line 97 of file qlayout.h.


The documentation for this class was generated from the following files: