143 qWarning(
"QLayout: Attempting to add QLayout \"%s\" to %s \"%s\", which" 144 " already has a layout",
150 w->d_func()->
layout =
this;
162 :
QObjectPrivate(), insideSpacing(-1), userLeftMargin(-1), userTopMargin(-1), userRightMargin(-1),
163 userBottomMargin(-1), topLevel(false),
enabled(true), activated(true), autoNewChild(false),
174 if (userMargin >= 0) {
175 *result = userMargin;
179 *result = pw->style()->pixelMetric(pm, 0, pw);
229 d->insideSpacing = margin;
231 d->insideSpacing = spacing;
234 qWarning(
"QLayout \"%s\" added to %s \"%s\", which already has a layout",
240 parent->d_func()->
layout =
this;
244 parent->d_func()->
layout = 0;
265 d->insideSpacing = spacing;
282 d->insideSpacing = spacing;
289 void QLayout::setAutoAdd(
bool a) {
Q_D(
QLayout);
d->autoNewChild =
a; }
295 bool QLayout::autoAdd()
const {
Q_D(
const QLayout);
return d->autoNewChild; }
337 if (item->
widget() == w) {
414 getContentsMargins(&left, &top, &right, &bottom);
415 if (left == top && top == right && right == bottom) {
444 if (
const QBoxLayout* boxlayout = qobject_cast<const QBoxLayout*>(
this)) {
445 return boxlayout->spacing();
446 }
else if (
const QGridLayout* gridlayout = qobject_cast<const QGridLayout*>(
this)) {
447 return gridlayout->spacing();
448 }
else if (
const QFormLayout* formlayout = qobject_cast<const QFormLayout*>(
this)) {
449 return formlayout->spacing();
452 if (
d->insideSpacing >=0) {
453 return d->insideSpacing;
466 setContentsMargins(margin, margin, margin, margin);
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);
479 d->insideSpacing = spacing;
506 if (
d->userLeftMargin == left &&
d->userTopMargin == top &&
507 d->userRightMargin == right &&
d->userBottomMargin == bottom)
510 d->userLeftMargin =
left;
511 d->userTopMargin = top;
512 d->userRightMargin =
right;
513 d->userBottomMargin = bottom;
576 getContentsMargins(&left, &top, &right, &bottom);
577 return QMargins(left, top, right, bottom);
595 getContentsMargins(&left, &top, &right, &bottom);
596 return d->rect.adjusted(+left, +top, -right, -bottom);
600 bool QLayout::isTopLevel()
const 623 qWarning(
"QLayout::parentWidget: A layout can only have another layout as a parent.");
687 while ((child = lay->
itemAt(i))) {
688 if (child->
widget() == w) {
709 q->setGeometry(rect);
710 #ifndef QT_NO_MENUBAR 736 d->doResize(r->
size());
746 #ifndef QT_NO_MENUBAR 755 case QEvent::ChildInserted:
756 if (
d->topLevel &&
d->autoNewChild) {
761 #if !defined(QT_NO_MENUBAR) && !defined(QT_NO_TOOLBAR) 767 #ifndef QT_NO_SIZEGRIP 768 if (qobject_cast<QSizeGrip*>(w) ) {
777 case QEvent::LayoutHint:
778 d->activated =
false;
782 if (static_cast<QWidget *>(
parent())->isVisible())
804 while ((item = itemAt(i))) {
805 if (item == static_cast<QLayout*>(c->
child())) {
834 int h = heightForWidth(w - side) + top;
835 #ifndef QT_NO_MENUBAR 860 QSize s = minimumSize();
861 #ifndef QT_NO_MENUBAR 864 return s +
QSize(side, top);
886 QSize s = sizeHint();
887 if (hasHeightForWidth())
889 #ifndef QT_NO_MENUBAR 892 return s +
QSize(side, top);
914 QSize s = maximumSize();
915 #ifndef QT_NO_MENUBAR 943 if (
d->topLevel && parent() &&
parent()->isWidgetType() &&
952 void QLayout::deleteAllItems()
955 while ((l = takeAt(0)))
972 qWarning(
"QLayout::addChildLayout: layout \"%s\" already has a parent",
979 l->d_func()->reparentChildWidgets(mw);
989 const bool ok = !layout->
parent();
990 addChildLayout(layout);
997 static int checked_env = -1;
998 if(checked_env == -1)
1010 #ifndef QT_NO_MENUBAR 1016 for (
int i = 0; i < n; ++i) {
1022 qWarning(
"QLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent",
1023 w->metaObject()->className(), w->objectName().toLocal8Bit().data());
1032 l->d_func()->reparentChildWidgets(mw);
1057 qWarning(
"QLayout::addChildWidget: %s \"%s\" is already in a layout; moved to new layout",
1062 if (pw && mw && pw != mw) {
1065 qWarning(
"QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent",
1102 void QLayout::freeze(
int w,
int h)
1107 if (w <= 0 || h <= 0) {
1108 QSize s = totalSizeHint();
1112 setSizeConstraint(SetNoConstraint);
1135 #ifdef Q_OS_WINCE_WM 1140 addChildWidget(widget);
1210 while ((child = layout->
itemAt(i++)))
1211 activateRecursiveHelper(child);
1212 layout->d_func()->activated =
true;
1228 while (layout && layout->d_func()->activated) {
1229 layout->d_func()->activated =
false;
1230 if (layout->d_func()->topLevel) {
1252 if (!
d->enabled || !parent())
1260 qWarning(
"QLayout::activate: %s \"%s\" does not have a main widget",
1264 activateRecursiveHelper(
this);
1270 switch (
d->constraint) {
1275 case SetMinimumSize:
1278 case SetMaximumSize:
1281 case SetMinAndMaxSize:
1285 case SetDefaultConstraint: {
1289 QSize ms = totalMinimumSize();
1294 if ((!heightSet || !widthSet) && hasHeightForWidth()) {
1304 }
else if (!widthSet || !heightSet) {
1314 case SetNoConstraint:
1318 d->doResize(mw->
size());
1438 if (constraint ==
d->constraint)
1448 return d->constraint;
1461 QSize s = sizeHint();
1462 Qt::Alignment
a = alignment();
1481 }
else if (hasHeightForWidth()) {
1482 int hfw = heightForWidth(s.
width());
1520 while ((child = itemAt(i))) {
1543 while ((child = itemAt(i))) {
1544 if (child == item) {
1566 d->enabled = enable;
1595 if (current.
height() < currentHfw || currentHfw == newHfw) {
1609 while (minw < maxw) {
1610 if (minhfw > maxh) {
1611 minw = maxw - (maxw-minw)/2;
1613 }
else if (maxhfw < minh ) {
1614 maxw = minw + (maxw-minw)/2;
1662 if (type & (0x1 << i)) {
1663 data = (
data & ~CTMask) | (i << CTShift);
1675 #ifndef QT_NO_DATASTREAM 1689 return stream << policy.
data;
1705 return stream >> policy.
data;
1707 #endif // QT_NO_DATASTREAM
T qobject_cast(QObject *object)
static Qt::LayoutDirection layoutDirection()
void setEnabled(bool)
Enables this layout if enable is true, otherwise disables it.
int totalHeightForWidth(int w) const
Also takes contentsMargins and menu bar into account.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
The QBoxLayout class lines up child widgets horizontally or vertically.
#define QT_END_NAMESPACE
This macro expands to.
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
char * data()
Returns a pointer to the data stored in the byte array.
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...
virtual bool isEmpty() const =0
Implemented in subclasses to return whether this item is empty, i.
QRect contentsRect() const
Returns the layout's geometry() rectangle, but taking into account the contents margins.
Q_GUI_EXPORT QSize qSmartMaxSize(const QSize &sizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy, Qt::Alignment align)
static bool layoutDebug()
bool isEnabled() const
Returns true if the layout is enabled; otherwise returns false.
virtual void addItem(QLayoutItem *)=0
Implemented in subclasses to add an item.
virtual void invalidate()
Invalidates any cached information in this layout item.
void getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const
void removeItem(QLayoutItem *)
Removes the layout item item from the layout.
PixelMetric
This enum describes the various available pixel metrics.
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
static int menuBarHeightForWidth(QWidget *menubar, int w)
int width() const
Returns the width of the rectangle.
bool activate()
Redoes the layout for parentWidget() if necessary.
virtual int minimumHeightForWidth(int) const
Returns the minimum height this widget needs for the given width, w.
virtual void setGeometry(const QRect &)
Reimplemented Function
long ASN1_INTEGER_get ASN1_INTEGER * a
void invalidate()
Reimplemented Function
int height() const
Returns the height of the rectangle.
void setHeight(int h)
Sets the height to the given height.
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false...
static QWidgetItemFactoryMethod widgetItemFactoryMethod
The QObject class is the base class of all Qt objects.
static QSpacerItemFactoryMethod spacerItemFactoryMethod
QWidget * menuBar() const
Returns the menu bar set for this layout, or 0 if no menu bar is set.
static QSize closestAcceptableSize(const QWidget *w, const QSize &s)
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is ...
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setParent(QObject *)
Makes the object a child of parent.
Qt::Orientations expandingDirections() const
Returns whether this layout can make use of more space than sizeHint().
QSize maximumSize() const
Returns the maximum size of this layout.
int top() const
Returns the top margin.
void setWidth(int w)
Sets the width to the given width.
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
int width() const
Returns the width.
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.
void setAlignment(Qt::Alignment a)
Sets the alignment of this item to alignment.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QSize totalMaximumSize() const
Also takes contentsMargins and menu bar into account.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
QLayout()
Constructs a new child QLayout.
bool adoptLayout(QLayout *layout)
QWidgetItem *(* QWidgetItemFactoryMethod)(const QLayout *layout, QWidget *widget)
The QSpacerItem class provides blank space in a layout.
virtual int indexOf(QWidget *) const
Searches for widget widget in this layout (not including child layouts).
void update()
Updates the layout for parentWidget().
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
The QLayout class is the base class of geometry managers.
~QLayout()
Destroys the layout, deleting all child layouts.
QSize size() const
Returns the size of the rectangle.
QMargins contentsMargins() const
Returns the margins used around the layout.
The QResizeEvent class contains event parameters for resize events.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static QSpacerItem * createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy=QSizePolicy::Minimum, QSizePolicy::Policy vPolicy=QSizePolicy::Minimum)
void setMenuBar(QWidget *w)
Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins().
QSpacerItem *(* QSpacerItemFactoryMethod)(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy)
QLayout::SizeConstraint constraint
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
QRect alignmentRect(const QRect &) const
Returns the rectangle that should be covered when the geometry of this layout is set to r...
static QWidget * parentWidget(const QWidget *w)
bool isEmpty() const
Reimplemented Function
static void activateRecursiveHelper(QLayoutItem *item)
The QChildEvent class contains event parameters for child object events.
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
SizeConstraint
The possible values are:
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
int top() const
Returns the y-coordinate of the rectangle's top edge.
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...
Q_GUI_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)
void setControlType(ControlType type)
int y() const
Returns the y-coordinate of the rectangle's top edge.
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
const QSize & size() const
Returns the new size of the widget.
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
QDataStream & operator>>(QDataStream &s, QAxBase &c)
QSize totalSizeHint() const
Also takes contentsMargins and menu bar into account.
void addChildLayout(QLayout *l)
This function is called from addLayout() or insertLayout() functions in subclasses to add layout l as...
int x() const
Returns the x-coordinate of the rectangle's left edge.
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
QObject * parent() const
Returns a pointer to the parent object.
The QGridLayout class lays out widgets in a grid.
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
QString objectName() const
int height() const
Returns the height.
The QRect class defines a rectangle in the plane using integer precision.
QSize minimumSize() const
Returns the minimum size of this layout.
void setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
QSize totalMinimumSize() const
Also takes contentsMargins and menu bar into account.
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
QDataStream & operator<<(QDataStream &s, const QAxBase &c)
int left() const
Returns the left margin.
void setSizeConstraint(SizeConstraint)
The QSize class defines the size of a two-dimensional object using integer point precision.
The QDataStream class provides serialization of binary data to a QIODevice.
static bool removeWidgetRecursively(QLayoutItem *li, QWidget *w)
QRect geometry() const
Reimplemented Function
void widgetEvent(QEvent *)
Performs child widget layout when the parent widget is resized.
The QMargins class defines the four margins of a rectangle.
static const int QLAYOUTSIZE_MAX
void doResize(const QSize &)
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
#define qPrintable(string)
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
ControlType controlType() const
int bottom() const
Returns the bottom margin.
SizeConstraint sizeConstraint() const
int right() const
Returns the right margin.
void childEvent(QChildEvent *e)
Reimplemented Function
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...
void reparentChildWidgets(QWidget *mw)
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QObject * child() const
Returns the child object that was added or removed.
void removeWidget(QWidget *w)
Removes the widget widget from the layout.