Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qlayout.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qlayout.h"
5
6#include "qapplication.h"
7#include "qlayoutengine_p.h"
8#if QT_CONFIG(menubar)
9#include "qmenubar.h"
10#endif
11#if QT_CONFIG(toolbar)
12#include "qtoolbar.h"
13#endif
14#if QT_CONFIG(sizegrip)
15#include "qsizegrip.h"
16#endif
17#include "qevent.h"
18#include "qstyle.h"
19#include "qvariant.h"
20#include "qwidget_p.h"
21#include "qlayout_p.h"
22
24
25static int menuBarHeightForWidth(QWidget *menubar, int w)
26{
27 if (menubar && !menubar->isHidden() && !menubar->isWindow()) {
28 int result = menubar->heightForWidth(qMax(w, menubar->minimumWidth()));
29 if (result == -1)
30 result = menubar->sizeHint().height();
31 const int min = qSmartMinSize(menubar).height();
32 result = qBound(min, result, menubar->maximumSize().height());
33 if (result != -1)
34 return result;
35 }
36 return 0;
37}
38
85{
86 if (!parent)
87 return;
88 parent->setLayout(this);
89}
90
94 : QObject(dd, lay ? static_cast<QObject*>(lay) : static_cast<QObject*>(w))
95{
96 Q_D(QLayout);
97 if (lay) {
98 lay->addItem(this);
99 } else if (w) {
100 if (Q_UNLIKELY(w->layout())) {
101 qWarning("QLayout: Attempting to add QLayout \"%ls\" to %s \"%ls\", which"
102 " already has a layout",
103 qUtf16Printable(QObject::objectName()), w->metaObject()->className(),
104 qUtf16Printable(w->objectName()));
105 setParent(nullptr);
106 } else {
107 d->topLevel = true;
108 w->d_func()->layout = this;
109 QT_TRY {
110 invalidate();
111 } QT_CATCH(...) {
112 w->d_func()->layout = nullptr;
114 }
115 }
116 }
117}
118
120 : QObjectPrivate(), insideSpacing(-1), userLeftMargin(-1), userTopMargin(-1), userRightMargin(-1),
121 userBottomMargin(-1), topLevel(false), enabled(true), activated(true), autoNewChild(false),
122 constraint(QLayout::SetDefaultConstraint), menubar(nullptr)
123{
124}
125
126void QLayoutPrivate::getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const
127{
128 if (!result)
129 return;
130
131 Q_Q(const QLayout);
132 if (userMargin >= 0) {
133 *result = userMargin;
134 } else if (!topLevel) {
135 *result = 0;
136 } else if (QWidget *pw = q->parentWidget()) {
137 *result = pw->style()->pixelMetric(pm, nullptr, pw);
138 } else {
139 *result = 0;
140 }
141}
142
143// Static item factory functions that allow for hooking things in Designer
144
147
149{
152 return wi;
153 return new QWidgetItemV2(widget);
154}
155
157{
159 if (QSpacerItem *si = (*spacerItemFactoryMethod)(layout, w, h, hPolicy, vPolicy))
160 return si;
161 return new QSpacerItem(w, h, hPolicy, vPolicy);
162}
163
164
165
187{
190}
191
192
193
200{
201 int i = 0;
203 while (item) {
204 if (item->widget() == w) {
205 item->setAlignment(alignment);
206 invalidate();
207 return true;
208 }
209 ++i;
210 item = itemAt(i);
211 }
212 return false;
213}
214
223{
224 int i = 0;
226 while (item) {
227 if (item->layout() == l) {
228 item->setAlignment(alignment);
229 invalidate();
230 return true;
231 }
232 ++i;
233 item = itemAt(i);
234 }
235 return false;
236}
237
256{
257 Q_D(const QLayout);
258 if (d->insideSpacing >=0) {
259 return d->insideSpacing;
260 } else {
261 // arbitrarily prefer horizontal spacing to vertical spacing
263 }
264}
265
267{
268 Q_D(QLayout);
269 d->insideSpacing = spacing;
270 invalidate();
271}
272
289{
290 Q_D(QLayout);
291
292 if (d->userLeftMargin == left && d->userTopMargin == top &&
293 d->userRightMargin == right && d->userBottomMargin == bottom)
294 return;
295
296 d->userLeftMargin = left;
297 d->userTopMargin = top;
298 d->userRightMargin = right;
299 d->userBottomMargin = bottom;
300 invalidate();
301}
302
314{
315 setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom());
316}
317
327{
328 setContentsMargins(-1, -1, -1, -1);
329}
330
347void QLayout::getContentsMargins(int *left, int *top, int *right, int *bottom) const
348{
349 Q_D(const QLayout);
350 d->getMargin(left, d->userLeftMargin, QStyle::PM_LayoutLeftMargin);
351 d->getMargin(top, d->userTopMargin, QStyle::PM_LayoutTopMargin);
352 d->getMargin(right, d->userRightMargin, QStyle::PM_LayoutRightMargin);
353 d->getMargin(bottom, d->userBottomMargin, QStyle::PM_LayoutBottomMargin);
354}
355
367{
368 int left, top, right, bottom;
370 return QMargins(left, top, right, bottom);
371}
372
382{
383 Q_D(const QLayout);
384 int left, top, right, bottom;
386 return d->rect.adjusted(+left, +top, -right, -bottom);
387}
388
389
400{
401 Q_D(const QLayout);
402 if (!d->topLevel) {
403 if (parent()) {
404 QLayout *parentLayout = qobject_cast<QLayout*>(parent());
405 if (Q_UNLIKELY(!parentLayout)) {
406 qWarning("QLayout::parentWidget: A layout can only have another layout as a parent.");
407 return nullptr;
408 }
409 return parentLayout->parentWidget();
410 } else {
411 return nullptr;
412 }
413 } else {
415 return static_cast<QWidget *>(parent());
416 }
417}
418
423{
424 int i = 0;
426 while (item) {
427 if (!item->isEmpty())
428 return false;
429 ++i;
430 item = itemAt(i);
431 }
432 return true;
433}
434
438QSizePolicy::ControlTypes QLayout::controlTypes() const
439{
440 if (count() == 0)
442 QSizePolicy::ControlTypes types;
443 for (int i = count() - 1; i >= 0; --i)
444 types |= itemAt(i)->controlTypes();
445 return types;
446}
447
452{
453 Q_D(QLayout);
454 d->rect = r;
455}
456
461{
462 Q_D(const QLayout);
463 return d->rect;
464}
465
470{
471 Q_D(QLayout);
472 d->rect = QRect();
473 update();
474}
475
477{
478 QLayout *lay = li->layout();
479 if (!lay)
480 return false;
481 int i = 0;
483 while ((child = lay->itemAt(i))) {
484 if (child->widget() == w) {
485 delete lay->takeAt(i);
486 lay->invalidate();
487 return true;
488 } else if (removeWidgetRecursively(child, w)) {
489 return true;
490 } else {
491 ++i;
492 }
493 }
494 return false;
495}
496
497
499{
500 Q_Q(QLayout);
501 QWidget *mw = q->parentWidget();
503 const int mbh = menuBarHeightForWidth(menubar, rect.width());
504 const int mbTop = rect.top();
505 rect.setTop(mbTop + mbh);
506 q->setGeometry(rect);
507#if QT_CONFIG(menubar)
508 if (menubar)
509 menubar->setGeometry(rect.left(), mbTop, rect.width(), mbh);
510#endif
511}
512
513
521{
522 Q_D(QLayout);
523 if (!d->enabled)
524 return;
525
526 switch (e->type()) {
527 case QEvent::Resize:
528 if (d->activated)
529 d->doResize();
530 else
531 activate();
532 break;
534 {
536 QObject *child = c->child();
538 if (op->wasWidget) {
539#if QT_CONFIG(menubar)
540 if (child == d->menubar)
541 d->menubar = nullptr;
542#endif
544 }
545 }
546 break;
548 if (static_cast<QWidget *>(parent())->isVisible())
549 activate();
550 break;
551 default:
552 break;
553 }
554}
555
560{
561 Q_D(QLayout);
562 if (!d->enabled)
563 return;
564
565 if (e->type() != QEvent::ChildRemoved)
566 return;
567
568 if (QLayout *childLayout = qobject_cast<QLayout *>(e->child()))
569 removeItem(childLayout);
570}
571
577{
578 Q_D(const QLayout);
579 int side=0, top=0;
580 if (d->topLevel) {
582 parent->ensurePolished();
583 QWidgetPrivate *wd = parent->d_func();
584 side += wd->leftmargin + wd->rightmargin;
585 top += wd->topmargin + wd->bottommargin;
586 }
587 int h = minimumHeightForWidth(w - side) + top;
588#if QT_CONFIG(menubar)
589 h += menuBarHeightForWidth(d->menubar, w);
590#endif
591 return h;
592}
593
599{
600 Q_D(const QLayout);
601 int side=0, top=0;
602 if (d->topLevel) {
604 parent->ensurePolished();
605 QWidgetPrivate *wd = parent->d_func();
606 side += wd->leftmargin + wd->rightmargin;
607 top += wd->topmargin + wd->bottommargin;
608 }
609 int h = heightForWidth(w - side) + top;
610#if QT_CONFIG(menubar)
611 h += menuBarHeightForWidth(d->menubar, w);
612#endif
613 return h;
614}
615
621{
622 Q_D(const QLayout);
623 int side=0, top=0;
624 if (d->topLevel) {
625 QWidget *pw = parentWidget();
626 pw->ensurePolished();
627 QWidgetPrivate *wd = pw->d_func();
628 side += wd->leftmargin + wd->rightmargin;
629 top += wd->topmargin + wd->bottommargin;
630 }
631
632 QSize s = minimumSize();
633#if QT_CONFIG(menubar)
634 top += menuBarHeightForWidth(d->menubar, s.width() + side);
635#endif
636 return s + QSize(side, top);
637}
638
644{
645 Q_D(const QLayout);
646 int side=0, top=0;
647 if (d->topLevel) {
648 QWidget *pw = parentWidget();
649 pw->ensurePolished();
650 QWidgetPrivate *wd = pw->d_func();
651 side += wd->leftmargin + wd->rightmargin;
652 top += wd->topmargin + wd->bottommargin;
653 }
654
655 QSize s = sizeHint();
656 if (hasHeightForWidth())
657 s.setHeight(heightForWidth(s.width() + side));
658#if QT_CONFIG(menubar)
659 top += menuBarHeightForWidth(d->menubar, s.width());
660#endif
661 return s + QSize(side, top);
662}
663
669{
670 Q_D(const QLayout);
671 int side=0, top=0;
672 if (d->topLevel) {
673 QWidget *pw = parentWidget();
674 pw->ensurePolished();
675 QWidgetPrivate *wd = pw->d_func();
676 side += wd->leftmargin + wd->rightmargin;
677 top += wd->topmargin + wd->bottommargin;
678 }
679
680 QSize s = maximumSize();
681#if QT_CONFIG(menubar)
682 top += menuBarHeightForWidth(d->menubar, s.width());
683#endif
684
685 if (d->topLevel)
686 s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX),
687 qMin(s.height() + top, QLAYOUTSIZE_MAX));
688 return s;
689}
690
700{
701 Q_D(QLayout);
702 if (d->topLevel && parent() && parent()->isWidgetType() && parentWidget()->layout() == this)
703 parentWidget()->d_func()->layout = nullptr;
704 else if (QLayout *parentLayout = qobject_cast<QLayout *>(parent()))
705 parentLayout->removeItem(this);
706}
707
708
719{
720 if (Q_UNLIKELY(childLayout->parent())) {
721 qWarning("QLayout::addChildLayout: layout %s \"%ls\" already has a parent",
722 childLayout->metaObject()->className(), qUtf16Printable(childLayout->objectName()));
723 return;
724 }
725 childLayout->setParent(this);
726
727 if (QWidget *mw = parentWidget()) {
728 childLayout->d_func()->reparentChildWidgets(mw);
729 }
730
731}
732
737{
738 const bool ok = !layout->parent();
740 return ok;
741}
742
743#ifdef QT_DEBUG
744static bool layoutDebug()
745{
746 static int checked_env = -1;
747 if (checked_env == -1)
748 checked_env = !!qEnvironmentVariableIntValue("QT_LAYOUT_DEBUG");
749
750 return checked_env;
751}
752#endif
753
755{
756 Q_Q(QLayout);
757 int n = q->count();
758
759#if QT_CONFIG(menubar)
760 if (menubar && menubar->parentWidget() != mw) {
761 menubar->setParent(mw);
762 }
763#endif
764 bool mwVisible = mw && mw->isVisible();
765 for (int i = 0; i < n; ++i) {
766 QLayoutItem *item = q->itemAt(i);
767 if (QWidget *w = item->widget()) {
768 QWidget *pw = w->parentWidget();
769#ifdef QT_DEBUG
770 if (Q_UNLIKELY(pw && pw != mw && layoutDebug())) {
771 qWarning("QLayout::addChildLayout: widget %s \"%ls\" in wrong parent; moved to correct parent",
772 w->metaObject()->className(), qUtf16Printable(w->objectName()));
773 }
774#endif
775 bool needShow = mwVisible && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
776 if (pw != mw)
777 w->setParent(mw);
778 if (needShow)
779 QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later
780 } else if (QLayout *l = item->layout()) {
781 l->d_func()->reparentChildWidgets(mw);
782 }
783 }
784}
785
791{
792 Q_Q(const QLayout);
793 if (Q_UNLIKELY(!widget)) {
794 qWarning("QLayout: Cannot add a null widget to %s/%ls", q->metaObject()->className(),
795 qUtf16Printable(q->objectName()));
796 return false;
797 }
798 if (Q_UNLIKELY(widget == q->parentWidget())) {
799 qWarning("QLayout: Cannot add parent widget %s/%ls to its child layout %s/%ls",
800 widget->metaObject()->className(), qUtf16Printable(widget->objectName()),
801 q->metaObject()->className(), qUtf16Printable(q->objectName()));
802 return false;
803 }
804 return true;
805}
806
811bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const
812{
813 Q_Q(const QLayout);
814 if (Q_UNLIKELY(!otherLayout)) {
815 qWarning("QLayout: Cannot add a null layout to %s/%ls",
816 q->metaObject()->className(), qUtf16Printable(q->objectName()));
817 return false;
818 }
819 if (Q_UNLIKELY(otherLayout == q)) {
820 qWarning("QLayout: Cannot add layout %s/%ls to itself",
821 q->metaObject()->className(), qUtf16Printable(q->objectName()));
822 return false;
823 }
824 return true;
825}
826
837{
838 QWidget *mw = parentWidget();
839 QWidget *pw = w->parentWidget();
840
841 //Qt::WA_LaidOut is never reset. It only means that the widget at some point has
842 //been in a layout.
843 if (pw && w->testAttribute(Qt::WA_LaidOut)) {
844 QLayout *l = pw->layout();
845 if (l && removeWidgetRecursively(l, w)) {
846#ifdef QT_DEBUG
847 if (Q_UNLIKELY(layoutDebug()))
848 qWarning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout",
849 w->metaObject()->className(), qUtf16Printable(w->objectName()));
850#endif
851 }
852 }
853 if (pw && mw && pw != mw) {
854#ifdef QT_DEBUG
855 if (Q_UNLIKELY(layoutDebug()))
856 qWarning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent",
857 w->metaObject()->className(), qUtf16Printable(w->objectName()));
858#endif
859 pw = nullptr;
860 }
861 bool needShow = mw && mw->isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
862 if (!pw && mw)
863 w->setParent(mw);
864 w->setAttribute(Qt::WA_LaidOut);
865 if (needShow)
866 QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later
867}
868
869
870
871
872
873
874
875
882{
883 Q_D(QLayout);
884 if (widget)
886 d->menubar = widget;
887}
888
895{
896 Q_D(const QLayout);
897 return d->menubar;
898}
899
900
912{
913 return QSize(0, 0);
914}
915
927{
929}
930
943Qt::Orientations QLayout::expandingDirections() const
944{
946}
947
948void QLayout::activateRecursiveHelper(QLayoutItem *item)
949{
950 item->invalidate();
951 QLayout *layout = item->layout();
952 if (layout) {
954 int i=0;
955 while ((child = layout->itemAt(i++)))
956 activateRecursiveHelper(child);
957 layout->d_func()->activated = true;
958 }
959}
960
971{
972 QLayout *layout = this;
973 while (layout && layout->d_func()->activated) {
974 layout->d_func()->activated = false;
975 if (layout->d_func()->topLevel) {
977 QWidget *mw = static_cast<QWidget*>(layout->parent());
979 break;
980 }
981 layout = static_cast<QLayout*>(layout->parent());
982 }
983}
984
995{
996 Q_D(QLayout);
997 if (!d->enabled || !parent())
998 return false;
999 if (!d->topLevel)
1000 return static_cast<QLayout*>(parent())->activate();
1001 if (d->activated)
1002 return false;
1003 QWidget *mw = static_cast<QWidget*>(parent());
1004 if (Q_UNLIKELY(!mw)) {
1005 qWarning("QLayout::activate: %s \"%ls\" does not have a main widget",
1007 return false;
1008 }
1009 activateRecursiveHelper(this);
1010
1011 QWidgetPrivate *md = mw->d_func();
1012 uint explMin = md->extra ? md->extra->explicitMinSize : 0;
1013 uint explMax = md->extra ? md->extra->explicitMaxSize : 0;
1014
1015 switch (d->constraint) {
1016 case SetFixedSize:
1017 // will trigger resize
1019 break;
1020 case SetMinimumSize:
1022 break;
1023 case SetMaximumSize:
1025 break;
1026 case SetMinAndMaxSize:
1029 break;
1030 case SetDefaultConstraint: {
1031 bool widthSet = explMin & Qt::Horizontal;
1032 bool heightSet = explMin & Qt::Vertical;
1033 if (mw->isWindow()) {
1034 QSize ms = totalMinimumSize();
1035 if (widthSet)
1036 ms.setWidth(mw->minimumSize().width());
1037 if (heightSet)
1038 ms.setHeight(mw->minimumSize().height());
1039 mw->setMinimumSize(ms);
1040 } else if (!widthSet || !heightSet) {
1041 QSize ms = mw->minimumSize();
1042 if (!widthSet)
1043 ms.setWidth(0);
1044 if (!heightSet)
1045 ms.setHeight(0);
1046 mw->setMinimumSize(ms);
1047 }
1048 break;
1049 }
1050 case SetNoConstraint:
1051 break;
1052 }
1053
1054 d->doResize();
1055
1056 if (md->extra) {
1057 md->extra->explicitMinSize = explMin;
1058 md->extra->explicitMaxSize = explMax;
1059 }
1060 // ideally only if sizeHint() or sizePolicy() has changed
1061 mw->updateGeometry();
1062 return true;
1063}
1064
1089QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options)
1090{
1091 Q_D(QLayout);
1092 if (!from || !to)
1093 return nullptr;
1094 if (from == to) // Do not return a QLayoutItem for \a from, since ownership still
1095 return nullptr; // belongs to the layout (since nothing was changed)
1096
1097 int index = -1;
1098 QLayoutItem *item = nullptr;
1099 for (int u = 0; u < count(); ++u) {
1100 item = itemAt(u);
1101 if (!item)
1102 continue;
1103
1104 if (item->widget() == from) {
1105 index = u;
1106 break;
1107 }
1108
1109 if (item->layout() && (options & Qt::FindChildrenRecursively)) {
1110 QLayoutItem *r = item->layout()->replaceWidget(from, to, options);
1111 if (r)
1112 return r;
1113 }
1114 }
1115 if (index == -1)
1116 return nullptr;
1117
1118 addChildWidget(to);
1119 QLayoutItem *newitem = new QWidgetItem(to);
1120 newitem->setAlignment(item->alignment());
1121 QLayoutItem *r = d->replaceAt(index, newitem);
1122 if (!r)
1123 delete newitem;
1124 return r;
1125}
1126
1177{
1178 const int c = count();
1179
1180 for (int i = 0; i < c; ++i) {
1181 if (itemAt(i)->widget() == widget)
1182 return i;
1183 }
1184
1185 return -1;
1186}
1187
1196{
1197 const int c = count();
1198
1199 for (int i = 0; i < c; ++i) {
1200 if (itemAt(i) == layoutItem)
1201 return i;
1202 }
1203
1204 return -1;
1205}
1206
1241{
1242 Q_D(QLayout);
1243 if (constraint == d->constraint)
1244 return;
1245
1246 d->constraint = constraint;
1247 invalidate();
1248}
1249
1251{
1252 Q_D(const QLayout);
1253 return d->constraint;
1254}
1255
1265{
1266 QSize s = sizeHint();
1267 Qt::Alignment a = alignment();
1268
1269 /*
1270 This is a hack to obtain the real maximum size, not
1271 QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX), the value consistently
1272 returned by QLayoutItems that have an alignment.
1273 */
1274 QLayout *that = const_cast<QLayout *>(this);
1275 that->setAlignment({ });
1276 QSize ms = that->maximumSize();
1277 that->setAlignment(a);
1278
1281 s.setWidth(qMin(r.width(), ms.width()));
1282 }
1285 s.setHeight(qMin(r.height(), ms.height()));
1286 } else if (hasHeightForWidth()) {
1287 int hfw = heightForWidth(s.width());
1288 if (hfw < s.height())
1289 s.setHeight(qMin(hfw, ms.height()));
1290 }
1291
1292 s = s.boundedTo(r.size());
1293 int x = r.x();
1294 int y = r.y();
1295
1296 if (a & Qt::AlignBottom)
1297 y += (r.height() - s.height());
1298 else if (!(a & Qt::AlignTop))
1299 y += (r.height() - s.height()) / 2;
1300
1303 if (a & Qt::AlignRight)
1304 x += (r.width() - s.width());
1305 else if (!(a & Qt::AlignLeft))
1306 x += (r.width() - s.width()) / 2;
1307
1308 return QRect(x, y, s.width(), s.height());
1309}
1310
1323{
1324 if (Q_UNLIKELY(!widget)) {
1325 qWarning("QLayout::removeWidget: Cannot remove a null widget.");
1326 return;
1327 }
1328
1329 int i = 0;
1331 while ((child = itemAt(i))) {
1332 if (child->widget() == widget) {
1333 delete takeAt(i);
1334 invalidate();
1335 } else {
1336 ++i;
1337 }
1338 }
1339}
1340
1351{
1352 int i = 0;
1354 while ((child = itemAt(i))) {
1355 if (child == item) {
1356 takeAt(i);
1357 invalidate();
1358 } else {
1359 ++i;
1360 }
1361 }
1362}
1363
1375{
1376 Q_D(QLayout);
1377 d->enabled = enable;
1378}
1379
1386{
1387 Q_D(const QLayout);
1388 return d->enabled;
1389}
1390
1398{
1401 QLayout *l = widget->layout();
1402 if (l && l->hasHeightForWidth() && result.height() < l->minimumHeightForWidth(result.width()) ) {
1403 QSize current = widget->size();
1404 int currentHfw = l->minimumHeightForWidth(current.width());
1405 int newHfw = l->minimumHeightForWidth(result.width());
1406 if (current.height() < currentHfw || currentHfw == newHfw) {
1407 //handle the constant hfw case and the vertical-only case, as well as the
1408 // current-size-is-not-correct case
1409 result.setHeight(newHfw);
1410 } else {
1411 // binary search; assume hfw is decreasing ###
1412
1413 int maxw = qMax(widget->width(),result.width());
1414 int maxh = qMax(widget->height(), result.height());
1415 int minw = qMin(widget->width(),result.width());
1416 int minh = qMin(widget->height(), result.height());
1417
1418 int minhfw = l->minimumHeightForWidth(minw);
1419 int maxhfw = l->minimumHeightForWidth(maxw);
1420 while (minw < maxw) {
1421 if (minhfw > maxh) { //assume decreasing
1422 minw = maxw - (maxw-minw)/2;
1423 minhfw = l->minimumHeightForWidth(minw);
1424 } else if (maxhfw < minh ) { //assume decreasing
1425 maxw = minw + (maxw-minw)/2;
1426 maxhfw = l->minimumHeightForWidth(maxw);
1427 } else {
1428 break;
1429 }
1430 }
1431 result = result.expandedTo(QSize(minw, minhfw));
1432 }
1433 }
1434 return result;
1435}
1436
1438
1439#include "moc_qlayout.cpp"
\inmodule QtCore
Definition qcoreevent.h:372
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
\inmodule QtCore
Definition qcoreevent.h:45
@ ChildRemoved
Definition qcoreevent.h:108
@ LayoutRequest
Definition qcoreevent.h:112
Qt::LayoutDirection layoutDirection
the default layout direction for this application
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition qlayoutitem.h:25
virtual QSizePolicy::ControlTypes controlTypes() const
Returns the control type(s) for the layout item.
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false.
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width, which is not used in this default...
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition qlayoutitem.h:45
virtual int minimumHeightForWidth(int) const
Returns the minimum height this widget needs for the given width, w.
virtual QWidget * widget() const
If this item manages a QWidget, returns that widget.
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
void setAlignment(Qt::Alignment a)
Sets the alignment of this item to alignment.
bool checkLayout(QLayout *otherLayout) const
Returns true if the otherLayout can be added to the layout; otherwise returns false.
Definition qlayout.cpp:811
void getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const
Definition qlayout.cpp:126
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
Definition qlayout.cpp:148
bool checkWidget(QWidget *widget) const
Returns true if the widget can be added to the layout; otherwise returns false.
Definition qlayout.cpp:790
QWidgetItem *(* QWidgetItemFactoryMethod)(const QLayout *layout, QWidget *widget)
Definition qlayout_p.h:34
static QWidgetItemFactoryMethod widgetItemFactoryMethod
Definition qlayout_p.h:49
void reparentChildWidgets(QWidget *mw)
Definition qlayout.cpp:754
void doResize()
Definition qlayout.cpp:498
QWidget * menubar
Definition qlayout_p.h:63
static QSpacerItem * createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy=QSizePolicy::Minimum, QSizePolicy::Policy vPolicy=QSizePolicy::Minimum)
Definition qlayout.cpp:156
static QSpacerItemFactoryMethod spacerItemFactoryMethod
Definition qlayout_p.h:50
QSpacerItem *(* QSpacerItemFactoryMethod)(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy)
Definition qlayout_p.h:35
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
QRect geometry() const override
\reimp
Definition qlayout.cpp:460
QSize totalSizeHint() const
Definition qlayout.cpp:643
int totalHeightForWidth(int w) const
Definition qlayout.cpp:598
void widgetEvent(QEvent *)
Definition qlayout.cpp:520
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition qlayout.cpp:1322
QSizePolicy::ControlTypes controlTypes() const override
\reimp
Definition qlayout.cpp:438
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:836
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
Definition qlayout.cpp:186
int totalMinimumHeightForWidth(int w) const
Definition qlayout.cpp:576
void childEvent(QChildEvent *e) override
\reimp
Definition qlayout.cpp:559
void update()
Updates the layout for parentWidget().
Definition qlayout.cpp:970
bool isEmpty() const override
\reimp
Definition qlayout.cpp:422
bool isEnabled() const
Returns true if the layout is enabled; otherwise returns false.
Definition qlayout.cpp:1385
QRect alignmentRect(const QRect &) const
Returns the rectangle that should be covered when the geometry of this layout is set to r,...
Definition qlayout.cpp:1264
int spacing
the spacing between widgets inside the layout
Definition qlayout.h:30
QSize maximumSize() const override
Returns the maximum size of this layout.
Definition qlayout.cpp:926
void unsetContentsMargins()
Definition qlayout.cpp:326
QRect contentsRect() const
Definition qlayout.cpp:381
virtual void setSpacing(int)
Definition qlayout.cpp:266
SizeConstraint sizeConstraint
the resize mode of the layout
Definition qlayout.h:33
void setSizeConstraint(SizeConstraint)
Definition qlayout.cpp:1240
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition qlayout.cpp:994
virtual void addItem(QLayoutItem *)=0
Implemented in subclasses to add an item.
QSize totalMaximumSize() const
Definition qlayout.cpp:668
QSize totalMinimumSize() const
Definition qlayout.cpp:620
SizeConstraint
The possible values are:
Definition qlayout.h:35
@ SetDefaultConstraint
Definition qlayout.h:36
@ SetMaximumSize
Definition qlayout.h:40
@ SetNoConstraint
Definition qlayout.h:37
@ SetFixedSize
Definition qlayout.h:39
@ SetMinimumSize
Definition qlayout.h:38
@ SetMinAndMaxSize
Definition qlayout.h:41
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Definition qlayout.cpp:347
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
static QSize closestAcceptableSize(const QWidget *w, const QSize &s)
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is ...
Definition qlayout.cpp:1397
virtual QLayoutItem * takeAt(int index)=0
Must be implemented in subclasses to remove the layout item at index from the layout,...
Qt::Orientations expandingDirections() const override
Returns whether this layout can make use of more space than sizeHint().
Definition qlayout.cpp:943
QLayout(QWidget *parent=nullptr)
Constructs a new top-level QLayout, with parent parent.
Definition qlayout.cpp:83
QMargins contentsMargins
Definition qlayout.h:32
QSize minimumSize() const override
Returns the minimum size of this layout.
Definition qlayout.cpp:911
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:199
void invalidate() override
\reimp
Definition qlayout.cpp:469
virtual QLayoutItem * replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options=Qt::FindChildrenRecursively)
Definition qlayout.cpp:1089
QWidget * menuBar() const
Returns the menu bar set for this layout, or \nullptr if no menu bar is set.
Definition qlayout.cpp:894
void setMenuBar(QWidget *w)
Tells the geometry manager to place the menu bar widget at the top of parentWidget(),...
Definition qlayout.cpp:881
QWidget * parentWidget() const
Returns the parent widget of this layout, or \nullptr if this layout is not installed on any widget.
Definition qlayout.cpp:399
void setEnabled(bool)
Enables this layout if enable is true, otherwise disables it.
Definition qlayout.cpp:1374
virtual int count() const =0
Must be implemented in subclasses to return the number of items in the layout.
bool adoptLayout(QLayout *layout)
Definition qlayout.cpp:736
virtual void setGeometry(const QRect &) override
\reimp
Definition qlayout.cpp:451
QLayout * layout() override
\reimp
void addChildLayout(QLayout *l)
This function is called from addLayout() or insertLayout() functions in subclasses to add layout chil...
Definition qlayout.cpp:718
void removeItem(QLayoutItem *)
Removes the layout item item from the layout.
Definition qlayout.cpp:1350
virtual int indexOf(const QWidget *) const
Searches for widget widget in this layout (not including child layouts).
Definition qlayout.cpp:1176
void setContentsMargins(int left, int top, int right, int bottom)
Definition qlayout.cpp:288
\inmodule QtCore
Definition qmargins.h:23
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:119
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:110
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:116
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:113
uint wasWidget
Definition qobject.h:74
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:153
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
QString objectName
the name of this object
Definition qobject.h:94
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2142
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition qobject.h:118
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:175
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:172
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr void setTop(int pos) noexcept
Sets the top edge of the rectangle to the given y coordinate.
Definition qrect.h:193
Policy
This enum describes the various per-dimension sizing types used when constructing a QSizePolicy.
Definition qsizepolicy.h:29
\inmodule QtCore
Definition qsize.h:25
constexpr QSize boundedTo(const QSize &) const noexcept
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition qsize.h:196
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition qsize.h:191
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:135
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:138
The QSpacerItem class provides blank space in a layout.
Definition qlayoutitem.h:57
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:2203
PixelMetric
This enum describes the various available pixel metrics.
Definition qstyle.h:413
@ PM_LayoutBottomMargin
Definition qstyle.h:513
@ PM_LayoutLeftMargin
Definition qstyle.h:510
@ PM_LayoutHorizontalSpacing
Definition qstyle.h:514
@ PM_LayoutTopMargin
Definition qstyle.h:511
@ PM_LayoutRightMargin
Definition qstyle.h:512
The QWidgetItem class is a layout item that represents a widget.
Definition qlayoutitem.h:86
short bottommargin
Definition qwidget_p.h:688
std::unique_ptr< QWExtra > extra
Definition qwidget_p.h:639
short rightmargin
Definition qwidget_p.h:687
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:886
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
void setMinimumSize(const QSize &)
Definition qwidget.h:832
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition qwidget.h:877
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QSize minimumSize
the widget's minimum size
Definition qwidget.h:120
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
QSize maximumSize
the widget's maximum size in pixels
Definition qwidget.h:121
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7753
int minimumWidth
the widget's minimum width in pixels
Definition qwidget.h:123
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void setMaximumSize(const QSize &)
Definition qwidget.h:835
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
QSize sizeHint
the recommended size for the widget
Definition qwidget.h:148
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition qwidget.h:811
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:4089
bool isVisible() const
Definition qwidget.h:874
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
QOpenGLWidget * widget
[1]
qreal spacing
double e
uint alignment
Combined button and popup list for selecting options.
@ AlignRight
Definition qnamespace.h:145
@ AlignBottom
Definition qnamespace.h:153
@ AlignTop
Definition qnamespace.h:152
@ AlignHorizontal_Mask
Definition qnamespace.h:150
@ AlignVertical_Mask
Definition qnamespace.h:160
@ AlignLeft
Definition qnamespace.h:143
@ WA_WState_ExplicitShowHide
Definition qnamespace.h:334
@ WA_LaidOut
Definition qnamespace.h:288
@ WA_LayoutOnEntireRect
Definition qnamespace.h:313
@ Horizontal
Definition qnamespace.h:98
@ Vertical
Definition qnamespace.h:99
@ FindChildrenRecursively
@ QueuedConnection
#define Q_UNLIKELY(x)
#define QT_RETHROW
#define QT_CATCH(A)
#define QT_TRY
static QT_BEGIN_NAMESPACE int menuBarHeightForWidth(QWidget *menubar, int w)
Definition qlayout.cpp:25
static bool removeWidgetRecursively(QLayoutItem *li, QObject *w)
Definition qlayout.cpp:476
Q_WIDGETS_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
Q_WIDGETS_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)
Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QSize &sizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy, Qt::Alignment align)
QT_BEGIN_NAMESPACE constexpr int QLAYOUTSIZE_MAX
Definition qlayoutitem.h:16
#define qWarning
Definition qlogging.h:162
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLboolean r
[2]
GLsizei GLenum GLenum * types
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint left
GLint GLint bottom
GLboolean enable
GLfloat n
GLint y
GLfloat GLfloat GLfloat GLfloat h
const GLubyte * c
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
static void layoutItem(QQuickItem *item, qreal y, qreal width)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define qUtf16Printable(string)
Definition qstring.h:1403
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
unsigned int uint
Definition qtypes.h:29
const char className[16]
[1]
Definition qwizard.cpp:100
obj metaObject() -> className()
QObject::connect nullptr
QVBoxLayout * layout
QGraphicsItem * item
edit isVisible()
QLayoutItem * child
[0]
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), 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())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent