Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qboxlayout.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 "qapplication.h"
5#include "qboxlayout.h"
6#include "qlist.h"
7#include "qsizepolicy.h"
8#include "qwidget.h"
9
10#include "qlayout_p.h"
11#include "qlayoutengine_p.h"
12
14
16{
17 QBoxLayoutItem(QLayoutItem *it, int stretch_ = 0)
18 : item(it), stretch(stretch_), magic(false) { }
19 ~QBoxLayoutItem() { delete item; }
20
21 int hfw(int w) {
22 if (item->hasHeightForWidth()) {
23 return item->heightForWidth(w);
24 } else {
25 return item->sizeHint().height();
26 }
27 }
28 int mhfw(int w) {
29 if (item->hasHeightForWidth()) {
31 } else {
32 return item->minimumSize().height();
33 }
34 }
35 int hStretch() {
36 if (stretch == 0 && item->widget()) {
37 return item->widget()->sizePolicy().horizontalStretch();
38 } else {
39 return stretch;
40 }
41 }
42 int vStretch() {
43 if (stretch == 0 && item->widget()) {
44 return item->widget()->sizePolicy().verticalStretch();
45 } else {
46 return stretch;
47 }
48 }
49
52 bool magic;
53};
54
56{
57 Q_DECLARE_PUBLIC(QBoxLayout)
58public:
59 QBoxLayoutPrivate() : hfwWidth(-1), dirty(true), spacing(-1) { }
61
62 void setDirty() {
64 hfwWidth = -1;
65 hfwHeight = -1;
66 dirty = true;
67 }
68
69 QList<QBoxLayoutItem *> list;
70 QList<QLayoutStruct> geomArray;
78 Qt::Orientations expanding;
83
84 inline void deleteAll() { while (!list.isEmpty()) delete list.takeFirst(); }
85
86 void setupGeom();
87 void calcHfw(int);
88
89 void effectiveMargins(int *left, int *top, int *right, int *bottom) const;
90 QLayoutItem* replaceAt(int index, QLayoutItem*) override;
91 int validateIndex(int index) const;
92};
93
97
98static inline bool horz(QBoxLayout::Direction dir)
99{
101}
102
108void QBoxLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *bottom) const
109{
110 int l = leftMargin;
111 int t = topMargin;
112 int r = rightMargin;
113 int b = bottomMargin;
114#ifdef Q_OS_MAC
115 Q_Q(const QBoxLayout);
116 if (horz(dir)) {
117 QBoxLayoutItem *leftBox = nullptr;
118 QBoxLayoutItem *rightBox = nullptr;
119
120 if (left || right) {
121 leftBox = list.value(0);
122 rightBox = list.value(list.count() - 1);
124 qSwap(leftBox, rightBox);
125
126 int leftDelta = 0;
127 int rightDelta = 0;
128 if (leftBox) {
129 QLayoutItem *itm = leftBox->item;
130 if (QWidget *w = itm->widget())
131 leftDelta = itm->geometry().left() - w->geometry().left();
132 }
133 if (rightBox) {
134 QLayoutItem *itm = rightBox->item;
135 if (QWidget *w = itm->widget())
136 rightDelta = w->geometry().right() - itm->geometry().right();
137 }
138 QWidget *w = q->parentWidget();
140 if (layoutDirection == Qt::RightToLeft)
141 qSwap(leftDelta, rightDelta);
142
143 l = qMax(l, leftDelta);
144 r = qMax(r, rightDelta);
145 }
146
147 int count = top || bottom ? list.count() : 0;
148 for (int i = 0; i < count; ++i) {
150 QLayoutItem *itm = box->item;
151 QWidget *w = itm->widget();
152 if (w) {
153 QRect lir = itm->geometry();
154 QRect wr = w->geometry();
155 if (top)
156 t = qMax(t, lir.top() - wr.top());
157 if (bottom)
158 b = qMax(b, wr.bottom() - lir.bottom());
159 }
160 }
161 } else { // vertical layout
162 QBoxLayoutItem *topBox = nullptr;
163 QBoxLayoutItem *bottomBox = nullptr;
164
165 if (top || bottom) {
166 topBox = list.value(0);
167 bottomBox = list.value(list.count() - 1);
169 qSwap(topBox, bottomBox);
170 }
171
172 if (top && topBox) {
173 QLayoutItem *itm = topBox->item;
174 QWidget *w = itm->widget();
175 if (w)
176 t = qMax(t, itm->geometry().top() - w->geometry().top());
177 }
178
179 if (bottom && bottomBox) {
180 QLayoutItem *itm = bottomBox->item;
181 QWidget *w = itm->widget();
182 if (w)
183 b = qMax(b, w->geometry().bottom() - itm->geometry().bottom());
184 }
185 }
186
187 int count = left || right ? list.count() : 0;
188 for (int i = 0; i < count; ++i) {
190 QLayoutItem *itm = box->item;
191 QWidget *w = itm->widget();
192 if (w) {
193 QRect lir = itm->geometry();
194 QRect wr = w->geometry();
195 if (left)
196 l = qMax(l, lir.left() - wr.left());
197 if (right)
198 r = qMax(r, wr.right() - lir.right());
199 }
200 }
201 }
202#endif
203 if (left)
204 *left = l;
205 if (top)
206 *top = t;
207 if (right)
208 *right = r;
209 if (bottom)
210 *bottom = b;
211}
212
213
214/*
215 Initializes the data structure needed by qGeomCalc and
216 recalculates max/min and size hint.
217*/
219{
220 if (!dirty)
221 return;
222
223 Q_Q(QBoxLayout);
224 int maxw = horz(dir) ? 0 : QLAYOUTSIZE_MAX;
225 int maxh = horz(dir) ? QLAYOUTSIZE_MAX : 0;
226 int minw = 0;
227 int minh = 0;
228 int hintw = 0;
229 int hinth = 0;
230
231 bool horexp = false;
232 bool verexp = false;
233
234 hasHfw = false;
235
236 int n = list.size();
238 QList<QLayoutStruct> a(n);
239
240 QSizePolicy::ControlTypes controlTypes1;
241 QSizePolicy::ControlTypes controlTypes2;
242 int fixedSpacing = q->spacing();
243 int previousNonEmptyIndex = -1;
244
245 QStyle *style = nullptr;
246 if (fixedSpacing < 0) {
247 if (QWidget *parentWidget = q->parentWidget())
248 style = parentWidget->style();
249 }
250
251 for (int i = 0; i < n; i++) {
253 QSize max = box->item->maximumSize();
254 QSize min = box->item->minimumSize();
255 QSize hint = box->item->sizeHint();
256 Qt::Orientations exp = box->item->expandingDirections();
257 bool empty = box->item->isEmpty();
258 int spacing = 0;
259
260 if (!empty) {
261 if (fixedSpacing >= 0) {
262 spacing = (previousNonEmptyIndex >= 0) ? fixedSpacing : 0;
263#ifdef Q_OS_MAC
264 if (!horz(dir) && previousNonEmptyIndex >= 0) {
265 QBoxLayoutItem *sibling = (dir == QBoxLayout::TopToBottom ? box : list.at(previousNonEmptyIndex));
266 if (sibling) {
267 QWidget *wid = sibling->item->widget();
268 if (wid)
269 spacing = qMax(spacing, sibling->item->geometry().top() - wid->geometry().top());
270 }
271 }
272#endif
273 } else {
274 controlTypes1 = controlTypes2;
275 controlTypes2 = box->item->controlTypes();
276 if (previousNonEmptyIndex >= 0) {
277 QSizePolicy::ControlTypes actual1 = controlTypes1;
278 QSizePolicy::ControlTypes actual2 = controlTypes2;
280 qSwap(actual1, actual2);
281
282 if (style) {
283 spacing = style->combinedLayoutSpacing(actual1, actual2,
285 nullptr, q->parentWidget());
286 if (spacing < 0)
287 spacing = 0;
288 }
289 }
290 }
291
292 if (previousNonEmptyIndex >= 0)
293 a[previousNonEmptyIndex].spacing = spacing;
294 previousNonEmptyIndex = i;
295 }
296
297 bool ignore = empty && box->item->widget(); // ignore hidden widgets
298 bool dummy = true;
299 if (horz(dir)) {
300 bool expand = (exp & Qt::Horizontal || box->stretch > 0);
301 horexp = horexp || expand;
302 maxw += spacing + max.width();
303 minw += spacing + min.width();
304 hintw += spacing + hint.width();
305 if (!ignore)
306 qMaxExpCalc(maxh, verexp, dummy,
307 max.height(), exp & Qt::Vertical, box->item->isEmpty());
308 minh = qMax(minh, min.height());
309 hinth = qMax(hinth, hint.height());
310
311 a[i].sizeHint = hint.width();
312 a[i].maximumSize = max.width();
313 a[i].minimumSize = min.width();
314 a[i].expansive = expand;
315 a[i].stretch = box->stretch ? box->stretch : box->hStretch();
316 } else {
317 bool expand = (exp & Qt::Vertical || box->stretch > 0);
318 verexp = verexp || expand;
319 maxh += spacing + max.height();
320 minh += spacing + min.height();
321 hinth += spacing + hint.height();
322 if (!ignore)
323 qMaxExpCalc(maxw, horexp, dummy,
324 max.width(), exp & Qt::Horizontal, box->item->isEmpty());
325 minw = qMax(minw, min.width());
326 hintw = qMax(hintw, hint.width());
327
328 a[i].sizeHint = hint.height();
329 a[i].maximumSize = max.height();
330 a[i].minimumSize = min.height();
331 a[i].expansive = expand;
332 a[i].stretch = box->stretch ? box->stretch : box->vStretch();
333 }
334
335 a[i].empty = empty;
336 a[i].spacing = 0; // might be initialized with a non-zero value in a later iteration
337 hasHfw = hasHfw || box->item->hasHeightForWidth();
338 }
339
340 geomArray = a;
341
342 expanding = (Qt::Orientations)
343 ((horexp ? Qt::Horizontal : 0)
344 | (verexp ? Qt::Vertical : 0));
345
346 minSize = QSize(minw, minh);
347 maxSize = QSize(maxw, maxh).expandedTo(minSize);
348 sizeHint = QSize(hintw, hinth).expandedTo(minSize).boundedTo(maxSize);
349
350 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
351 int left, top, right, bottom;
353 QSize extra(left + right, top + bottom);
354
355 minSize += extra;
356 maxSize += extra;
357 sizeHint += extra;
358
359 dirty = false;
360}
361
362/*
363 Calculates and stores the preferred height given the width \a w.
364*/
366{
367 QList<QLayoutStruct> &a = geomArray;
368 int n = a.size();
369 int h = 0;
370 int mh = 0;
371
372 Q_ASSERT(n == list.size());
373
374 if (horz(dir)) {
375 qGeomCalc(a, 0, n, 0, w);
376 for (int i = 0; i < n; i++) {
378 h = qMax(h, box->hfw(a.at(i).size));
379 mh = qMax(mh, box->mhfw(a.at(i).size));
380 }
381 } else {
382 for (int i = 0; i < n; ++i) {
384 int spacing = a.at(i).spacing;
385 h += box->hfw(w);
386 mh += box->mhfw(w);
387 h += spacing;
388 mh += spacing;
389 }
390 }
391 hfwWidth = w;
392 hfwHeight = h;
393 hfwMinHeight = mh;
394}
395
397{
398 Q_Q(QBoxLayout);
399 if (!item)
400 return nullptr;
402 if (!b)
403 return nullptr;
404 QLayoutItem *r = b->item;
405
406 b->item = item;
407 q->invalidate();
408 return r;
409}
410
412{
413 if (index < 0)
414 return list.size(); // append
415
416 Q_ASSERT_X(index >= 0 && index <= list.size(), "QBoxLayout::insert", "index out of range");
417 return index;
418}
419
530 : QLayout(*new QBoxLayoutPrivate, nullptr, parent)
531{
532 Q_D(QBoxLayout);
533 d->dir = dir;
534}
535
536
537
544{
545 Q_D(QBoxLayout);
546 d->deleteAll(); // must do it before QObject deletes children, so can't be in ~QBoxLayoutPrivate
547}
548
561{
562 Q_D(const QBoxLayout);
563 if (d->spacing >=0) {
564 return d->spacing;
565 } else {
566 return qSmartSpacing(this, d->dir == LeftToRight || d->dir == RightToLeft
569 }
570}
571
579{
580 Q_D(QBoxLayout);
581 d->spacing = spacing;
582 invalidate();
583}
584
589{
590 Q_D(const QBoxLayout);
591 if (d->dirty)
592 const_cast<QBoxLayout*>(this)->d_func()->setupGeom();
593 return d->sizeHint;
594}
595
600{
601 Q_D(const QBoxLayout);
602 if (d->dirty)
603 const_cast<QBoxLayout*>(this)->d_func()->setupGeom();
604 return d->minSize;
605}
606
611{
612 Q_D(const QBoxLayout);
613 if (d->dirty)
614 const_cast<QBoxLayout*>(this)->d_func()->setupGeom();
615
617
619 s.setWidth(QLAYOUTSIZE_MAX);
621 s.setHeight(QLAYOUTSIZE_MAX);
622 return s;
623}
624
629{
630 Q_D(const QBoxLayout);
631 if (d->dirty)
632 const_cast<QBoxLayout*>(this)->d_func()->setupGeom();
633 return d->hasHfw;
634}
635
640{
641 Q_D(const QBoxLayout);
642 if (!hasHeightForWidth())
643 return -1;
644
645 int left, top, right, bottom;
646 d->effectiveMargins(&left, &top, &right, &bottom);
647
648 w -= left + right;
649 if (w != d->hfwWidth)
650 const_cast<QBoxLayout*>(this)->d_func()->calcHfw(w);
651
652 return d->hfwHeight + top + bottom;
653}
654
659{
660 Q_D(const QBoxLayout);
662 int top, bottom;
663 d->effectiveMargins(nullptr, &top, nullptr, &bottom);
664 return d->hasHfw ? (d->hfwMinHeight + top + bottom) : -1;
665}
666
671{
672 Q_D(QBoxLayout);
673 d->setDirty();
675}
676
681{
682 Q_D(const QBoxLayout);
683 return d->list.size();
684}
685
690{
691 Q_D(const QBoxLayout);
692 return index >= 0 && index < d->list.size() ? d->list.at(index)->item : nullptr;
693}
694
699{
700 Q_D(QBoxLayout);
701 if (index < 0 || index >= d->list.size())
702 return nullptr;
703 QBoxLayoutItem *b = d->list.takeAt(index);
704 QLayoutItem *item = b->item;
705 b->item = nullptr;
706 delete b;
707
708 if (QLayout *l = item->layout()) {
709 // sanity check in case the user passed something weird to QObject::setParent()
710 if (l->parent() == this)
711 l->setParent(nullptr);
712 }
713
714 invalidate();
715 return item;
716}
717
718
722Qt::Orientations QBoxLayout::expandingDirections() const
723{
724 Q_D(const QBoxLayout);
725 if (d->dirty)
726 const_cast<QBoxLayout*>(this)->d_func()->setupGeom();
727 return d->expanding;
728}
729
734{
735 Q_D(QBoxLayout);
736 if (d->dirty || r != geometry()) {
737 QRect oldRect = geometry();
739 if (d->dirty)
740 d->setupGeom();
741 QRect cr = alignment() ? alignmentRect(r) : r;
742
743 int left, top, right, bottom;
744 d->effectiveMargins(&left, &top, &right, &bottom);
745 QRect s(cr.x() + left, cr.y() + top,
746 cr.width() - (left + right),
747 cr.height() - (top + bottom));
748
749 QList<QLayoutStruct> a = d->geomArray;
750 int pos = horz(d->dir) ? s.x() : s.y();
751 int space = horz(d->dir) ? s.width() : s.height();
752 int n = a.size();
753 if (d->hasHfw && !horz(d->dir)) {
754 for (int i = 0; i < n; i++) {
755 QBoxLayoutItem *box = d->list.at(i);
756 if (box->item->hasHeightForWidth()) {
757 int width = qBound(box->item->minimumSize().width(), s.width(), box->item->maximumSize().width());
758 a[i].sizeHint = a[i].minimumSize =
759 box->item->heightForWidth(width);
760 }
761 }
762 }
763
764 Direction visualDir = d->dir;
766 if (parent && parent->isRightToLeft()) {
767 if (d->dir == LeftToRight)
768 visualDir = RightToLeft;
769 else if (d->dir == RightToLeft)
770 visualDir = LeftToRight;
771 }
772
773 qGeomCalc(a, 0, n, pos, space);
774
775 bool reverse = (horz(visualDir)
776 ? ((r.right() > oldRect.right()) != (visualDir == RightToLeft))
777 : r.bottom() > oldRect.bottom());
778 for (int j = 0; j < n; j++) {
779 int i = reverse ? n-j-1 : j;
780 QBoxLayoutItem *box = d->list.at(i);
781
782 switch (visualDir) {
783 case LeftToRight:
784 box->item->setGeometry(QRect(a.at(i).pos, s.y(), a.at(i).size, s.height()));
785 break;
786 case RightToLeft:
787 box->item->setGeometry(QRect(s.left() + s.right() - a.at(i).pos - a.at(i).size + 1,
788 s.y(), a.at(i).size, s.height()));
789 break;
790 case TopToBottom:
791 box->item->setGeometry(QRect(s.x(), a.at(i).pos, s.width(), a.at(i).size));
792 break;
793 case BottomToTop:
794 box->item->setGeometry(QRect(s.x(),
795 s.top() + s.bottom() - a.at(i).pos - a.at(i).size + 1,
796 s.width(), a.at(i).size));
797 }
798 }
799 }
800}
801
806{
807 Q_D(QBoxLayout);
809 d->list.append(it);
810 invalidate();
811}
812
821{
822 Q_D(QBoxLayout);
823 index = d->validateIndex(index);
825 d->list.insert(index, it);
826 invalidate();
827}
828
839{
840 Q_D(QBoxLayout);
841 index = d->validateIndex(index);
842 QLayoutItem *b;
843 if (horz(d->dir))
845 else
847
849 it->magic = true;
850 d->list.insert(index, it);
851 invalidate();
852}
853
861void QBoxLayout::insertStretch(int index, int stretch)
862{
863 Q_D(QBoxLayout);
864 index = d->validateIndex(index);
865 QLayoutItem *b;
866 if (horz(d->dir))
868 else
870
872 it->magic = true;
873 d->list.insert(index, it);
874 invalidate();
875}
876
887{
888 Q_D(QBoxLayout);
889 index = d->validateIndex(index);
891 it->magic = true;
892 d->list.insert(index, it);
893 invalidate();
894}
895
905{
906 Q_D(QBoxLayout);
907 if (!d->checkLayout(layout))
908 return;
909 if (!adoptLayout(layout))
910 return;
911 index = d->validateIndex(index);
913 d->list.insert(index, it);
914 invalidate();
915}
916
938 Qt::Alignment alignment)
939{
940 Q_D(QBoxLayout);
941 if (!d->checkWidget(widget))
942 return;
944 index = d->validateIndex(index);
946 b->setAlignment(alignment);
947
949 d->list.insert(index, it);
950 invalidate();
951}
952
961{
962 insertSpacing(-1, size);
963}
964
971void QBoxLayout::addStretch(int stretch)
972{
974}
975
987
1008void QBoxLayout::addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
1009{
1011}
1012
1020{
1022}
1023
1032{
1033 Q_D(QBoxLayout);
1034 QLayoutItem *b;
1035 if (horz(d->dir))
1037 else
1039
1041 it->magic = true;
1042 d->list.append(it);
1043 invalidate();
1044}
1045
1054{
1055 Q_D(QBoxLayout);
1056 if (!widget)
1057 return false;
1058 for (int i = 0; i < d->list.size(); ++i) {
1059 QBoxLayoutItem *box = d->list.at(i);
1060 if (box->item->widget() == widget) {
1061 box->stretch = stretch;
1062 invalidate();
1063 return true;
1064 }
1065 }
1066 return false;
1067}
1068
1077{
1078 Q_D(QBoxLayout);
1079 for (int i = 0; i < d->list.size(); ++i) {
1080 QBoxLayoutItem *box = d->list.at(i);
1081 if (box->item->layout() == layout) {
1082 if (box->stretch != stretch) {
1083 box->stretch = stretch;
1084 invalidate();
1085 }
1086 return true;
1087 }
1088 }
1089 return false;
1090}
1091
1098void QBoxLayout::setStretch(int index, int stretch)
1099{
1100 Q_D(QBoxLayout);
1101 if (index >= 0 && index < d->list.size()) {
1102 QBoxLayoutItem *box = d->list.at(index);
1103 if (box->stretch != stretch) {
1104 box->stretch = stretch;
1105 invalidate();
1106 }
1107 }
1108}
1109
1117{
1118 Q_D(const QBoxLayout);
1119 if (index >= 0 && index < d->list.size())
1120 return d->list.at(index)->stretch;
1121 return -1;
1122}
1123
1128{
1129 Q_D(QBoxLayout);
1130 if (d->dir == direction)
1131 return;
1132 if (horz(d->dir) != horz(direction)) {
1133 //swap around the spacers (the "magic" bits)
1134 //#### a bit yucky, knows too much.
1135 //#### probably best to add access functions to spacerItem
1136 //#### or even a QSpacerItem::flip()
1137 for (int i = 0; i < d->list.size(); ++i) {
1138 QBoxLayoutItem *box = d->list.at(i);
1139 if (box->magic) {
1140 QSpacerItem *sp = box->item->spacerItem();
1141 if (sp) {
1142 if (sp->expandingDirections() == Qt::Orientations{} /*No Direction*/) {
1143 //spacing or strut
1144 QSize s = sp->sizeHint();
1145 sp->changeSize(s.height(), s.width(),
1148
1149 } else {
1150 //stretch
1151 if (horz(direction))
1152 sp->changeSize(0, 0, QSizePolicy::Expanding,
1154 else
1155 sp->changeSize(0, 0, QSizePolicy::Minimum,
1157 }
1158 }
1159 }
1160 }
1161 }
1162 d->dir = direction;
1163 invalidate();
1164}
1165
1176{
1177 Q_D(const QBoxLayout);
1178 return d->dir;
1179}
1180
1228 : QBoxLayout(LeftToRight, parent)
1229{
1230}
1231
1237 : QBoxLayout(LeftToRight)
1238{
1239}
1240
1241
1242
1243
1244
1253
1300 : QBoxLayout(TopToBottom, parent)
1301{
1302}
1303
1310 : QBoxLayout(TopToBottom)
1311{
1312}
1313
1314
1323
1325
1326#include "moc_qboxlayout.cpp"
QBoxLayout::Direction dir
QLayoutItem * replaceAt(int index, QLayoutItem *) override
void effectiveMargins(int *left, int *top, int *right, int *bottom) const
QList< QLayoutStruct > geomArray
int validateIndex(int index) const
QList< QBoxLayoutItem * > list
Qt::Orientations expanding
The QBoxLayout class lines up child widgets horizontally or vertically.
Definition qboxlayout.h:21
void setGeometry(const QRect &) override
\reimp
void invalidate() override
Resets cached information.
QSize minimumSize() const override
\reimp
int count() const override
\reimp
void insertStretch(int index, int stretch=0)
Inserts a stretchable space (a QSpacerItem) at position index, with zero minimum size and stretch fac...
void insertSpacing(int index, int size)
Inserts a non-stretchable space (a QSpacerItem) at position index, with size size.
int spacing() const override
Reimplements QLayout::spacing().
void insertLayout(int index, QLayout *layout, int stretch=0)
Inserts layout at position index, with stretch factor stretch.
QSize sizeHint() const override
\reimp
void addSpacerItem(QSpacerItem *spacerItem)
QSize maximumSize() const override
\reimp
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
QLayoutItem * takeAt(int) override
\reimp
int heightForWidth(int) const override
\reimp
void addStrut(int)
Limits the perpendicular dimension of the box (e.g.
Direction
This type is used to determine the direction of a box layout.
Definition qboxlayout.h:25
int minimumHeightForWidth(int) const override
\reimp
bool setStretchFactor(QWidget *w, int stretch)
Sets the stretch factor for widget to stretch and returns true if widget is found in this layout (not...
Direction direction() const
Returns the direction of the box.
void addItem(QLayoutItem *) override
\reimp
void addSpacing(int size)
Adds a non-stretchable space (a QSpacerItem) with size size to the end of this box layout.
void insertItem(int index, QLayoutItem *)
Inserts item into this box layout at position index.
bool hasHeightForWidth() const override
\reimp
~QBoxLayout()
Destroys this box layout.
void addStretch(int stretch=0)
Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end...
void insertSpacerItem(int index, QSpacerItem *spacerItem)
void setStretch(int index, int stretch)
Sets the stretch factor at position index.
Qt::Orientations expandingDirections() const override
\reimp
QLayoutItem * itemAt(int) const override
\reimp
QBoxLayout(Direction, QWidget *parent=nullptr)
Constructs a new QBoxLayout with direction dir and parent widget parent.
void insertWidget(int index, QWidget *widget, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Inserts widget at position index, with stretch factor stretch and alignment alignment.
void setDirection(Direction)
Sets the direction of this layout to direction.
void setSpacing(int spacing) override
Reimplements QLayout::setSpacing().
int stretch(int index) const
Returns the stretch factor at position index.
void addLayout(QLayout *layout, int stretch=0)
Adds layout to the end of the box, with serial stretch factor stretch.
Qt::LayoutDirection layoutDirection
the default layout direction for this application
~QHBoxLayout()
Destroys this box layout.
QHBoxLayout()
Constructs a new horizontal box.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition qlayoutitem.h:25
virtual QSize minimumSize() const =0
Implemented in subclasses to return the minimum size of this item.
virtual QRect geometry() const =0
Returns the rectangle covered by this 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...
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition qlayoutitem.h:45
virtual void setGeometry(const QRect &)=0
Implemented in subclasses to set this item's geometry to r.
virtual QSpacerItem * spacerItem()
If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise \nullptr is returned.
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.
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
Definition qlayout.cpp:148
static QSpacerItem * createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy=QSizePolicy::Minimum, QSizePolicy::Policy vPolicy=QSizePolicy::Minimum)
Definition qlayout.cpp:156
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
QRect geometry() const override
\reimp
Definition qlayout.cpp:460
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:837
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:1265
void invalidate() override
\reimp
Definition qlayout.cpp:469
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
bool adoptLayout(QLayout *layout)
Definition qlayout.cpp:737
virtual void setGeometry(const QRect &) override
\reimp
Definition qlayout.cpp:451
QLayout * layout() override
\reimp
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
value_type takeFirst()
Definition qlist.h:566
T value(qsizetype i) const
Definition qlist.h:664
qsizetype count() const noexcept
Definition qlist.h:398
void clear()
Definition qlist.h:434
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
iterator insert(const T &value)
Definition qset.h:155
\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:197
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
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:192
The QSpacerItem class provides blank space in a layout.
Definition qlayoutitem.h:57
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=nullptr, QWidget *widget=nullptr) const
Definition qstyle.cpp:2371
@ PM_LayoutVerticalSpacing
Definition qstyle.h:517
@ PM_LayoutHorizontalSpacing
Definition qstyle.h:516
QVBoxLayout()
Constructs a new vertical box.
~QVBoxLayout()
Destroys this box layout.
The QWidgetItem class is a layout item that represents a widget.
Definition qlayoutitem.h:86
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
Qt::LayoutDirection layoutDirection
the layout direction for this widget.
Definition qwidget.h:170
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QOpenGLWidget * widget
[1]
qreal spacing
QSet< QString >::iterator it
uint alignment
direction
Combined button and popup list for selecting options.
@ AlignHorizontal_Mask
Definition qnamespace.h:151
@ AlignVertical_Mask
Definition qnamespace.h:161
LayoutDirection
@ RightToLeft
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
static bool horz(QBoxLayout::Direction dir)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
Q_WIDGETS_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)
void qGeomCalc(QList< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
static void qMaxExpCalc(int &max, bool &exp, bool &empty, int boxmax, bool boxexp, bool boxempty)
QT_BEGIN_NAMESPACE constexpr int QLAYOUTSIZE_MAX
Definition qlayoutitem.h:16
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
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLboolean r
[2]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint GLsizei width
GLint left
GLint GLint bottom
GLfloat n
GLsizei const GLint * box
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QT_BEGIN_NAMESPACE constexpr void qSwap(T &value1, T &value2) noexcept(std::is_nothrow_swappable_v< T >)
Definition qswap.h:20
#define sp
unsigned int uint
Definition qtypes.h:34
QList< int > list
[14]
QObject::connect nullptr
QVBoxLayout * layout
QString dir
[11]
QGraphicsItem * item
int mhfw(int w)
QBoxLayoutItem(QLayoutItem *it, int stretch_=0)
int hfw(int w)
QLayoutItem * item