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
qgridlayout.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 "qgridlayout.h"
6#include "qlist.h"
7#include "qsizepolicy.h"
8#include "qvarlengtharray.h"
9#include "qwidget.h"
10
11#include "qlayoutengine_p.h"
12#include "qlayout_p.h"
13
15
22
23/*
24 Three internal classes related to QGridLayout: (1) QGridBox is a
25 QLayoutItem with (row, column) information and (torow, tocolumn) information; (3) QGridLayoutData is
26 the internal representation of a QGridLayout.
27*/
28
30{
31public:
32 QGridBox(QLayoutItem *lit) { item_ = lit; }
33
34 QGridBox(const QLayout *l, QWidget *wid) { item_ = QLayoutPrivate::createWidgetItem(l, wid); }
35 ~QGridBox() { delete item_; }
36
37 QSize sizeHint() const { return item_->sizeHint(); }
38 QSize minimumSize() const { return item_->minimumSize(); }
39 QSize maximumSize() const { return item_->maximumSize(); }
40 Qt::Orientations expandingDirections() const { return item_->expandingDirections(); }
41 bool isEmpty() const { return item_->isEmpty(); }
42
43 bool hasHeightForWidth() const { return item_->hasHeightForWidth(); }
44 int heightForWidth(int w) const { return item_->heightForWidth(w); }
45
46 void setAlignment(Qt::Alignment a) { item_->setAlignment(a); }
47 void setGeometry(const QRect &r) { item_->setGeometry(r); }
48 Qt::Alignment alignment() const { return item_->alignment(); }
49 QLayoutItem *item() { return item_; }
50 void setItem(QLayoutItem *newitem) { item_ = newitem; }
51 QLayoutItem *takeItem() { QLayoutItem *i = item_; item_ = nullptr; return i; }
52
53 int hStretch() { return item_->widget() ?
54 item_->widget()->sizePolicy().horizontalStretch() : 0; }
55 int vStretch() { return item_->widget() ?
56 item_->widget()->sizePolicy().verticalStretch() : 0; }
57
58private:
59 friend class QGridLayoutPrivate;
60 friend class QGridLayout;
61
62 inline int toRow(int rr) const { return torow >= 0 ? torow : rr - 1; }
63 inline int toCol(int cc) const { return tocol >= 0 ? tocol : cc - 1; }
64
65 QLayoutItem *item_;
66 int row, col;
67 int torow, tocol;
68};
69
71{
72 Q_DECLARE_PUBLIC(QGridLayout)
73public:
75
76 void add(QGridBox*, int row, int col);
77 void add(QGridBox*, int row1, int row2, int col1, int col2);
78 QSize sizeHint(int hSpacing, int vSpacing) const;
79 QSize minimumSize(int hSpacing, int vSpacing) const;
80 QSize maximumSize(int hSpacing, int vSpacing) const;
81
82 Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const;
83
84 void distribute(QRect rect, int hSpacing, int vSpacing);
85 inline int numRows() const { return rr; }
86 inline int numCols() const { return cc; }
87 inline void expand(int rows, int cols)
88 { setSize(qMax(rows, rr), qMax(cols, cc)); }
89 inline void setRowStretch(int r, int s)
90 { expand(r + 1, 0); rStretch[r] = s; setDirty(); }
91 inline void setColStretch(int c, int s)
92 { expand(0, c + 1); cStretch[c] = s; setDirty(); }
93 inline int rowStretch(int r) const { return rStretch.at(r); }
94 inline int colStretch(int c) const { return cStretch.at(c); }
95 inline void setRowMinimumHeight(int r, int s)
96 { expand(r + 1, 0); rMinHeights[r] = s; setDirty(); }
97 inline void setColumnMinimumWidth(int c, int s)
98 { expand(0, c + 1); cMinWidths[c] = s; setDirty(); }
99 inline int rowSpacing(int r) const { return rMinHeights.at(r); }
100 inline int colSpacing(int c) const { return cMinWidths.at(c); }
101
102 inline void setReversed(bool r, bool c) { hReversed = c; vReversed = r; }
103 inline bool horReversed() const { return hReversed; }
104 inline bool verReversed() const { return vReversed; }
105 inline void setDirty() { needRecalc = true; hfw_width = -1; }
106 inline bool isDirty() const { return needRecalc; }
107 bool hasHeightForWidth(int hSpacing, int vSpacing);
108 int heightForWidth(int width, int hSpacing, int vSpacing);
109 int minimumHeightForWidth(int width, int hSpacing, int vSpacing);
110
111 inline void getNextPos(int &row, int &col) { row = nextR; col = nextC; }
112 inline int count() const { return things.size(); }
113 QRect cellRect(int row, int col) const;
114
115 inline QLayoutItem *itemAt(int index) const {
116 if (index >= 0 && index < things.size())
117 return things.at(index)->item();
118 else
119 return nullptr;
120 }
121 inline QLayoutItem *takeAt(int index) {
122 Q_Q(QGridLayout);
123 if (index >= 0 && index < things.size()) {
124 if (QGridBox *b = things.takeAt(index)) {
125 QLayoutItem *item = b->takeItem();
126 if (QLayout *l = item->layout()) {
127 // sanity check in case the user passed something weird to QObject::setParent()
128 if (l->parent() == q)
129 l->setParent(nullptr);
130 }
131 delete b;
132 return item;
133 }
134 }
135 return nullptr;
136 }
137 QLayoutItem* replaceAt(int index, QLayoutItem *newitem) override
138 {
139 if (!newitem)
140 return nullptr;
141 QLayoutItem *item = nullptr;
142 QGridBox *b = things.value(index);
143 if (b) {
144 item = b->takeItem();
145 b->setItem(newitem);
146 }
147 return item;
148 }
149
150 void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const {
151 if (index >= 0 && index < things.size()) {
152 const QGridBox *b = things.at(index);
153 int toRow = b->toRow(rr);
154 int toCol = b->toCol(cc);
155 *row = b->row;
156 *column = b->col;
157 *rowSpan = toRow - *row + 1;
158 *columnSpan = toCol - *column +1;
159 }
160 }
161 void deleteAll();
162
163private:
164 void setNextPosAfter(int r, int c);
165 void recalcHFW(int w);
166 void addHfwData(QGridBox *box, int width);
167 void init();
168 QSize findSize(int QLayoutStruct::*, int hSpacing, int vSpacing) const;
169 void addData(QGridBox *b, const QGridLayoutSizeTriple &sizes, bool r, bool c);
170 void setSize(int rows, int cols);
171 void setupSpacings(QList<QLayoutStruct> &chain, QGridBox *grid[], int fixedSpacing,
172 Qt::Orientation orientation);
173 void setupLayoutData(int hSpacing, int vSpacing);
174 void setupHfwLayoutData();
175 void effectiveMargins(int *left, int *top, int *right, int *bottom) const;
176
177 int rr;
178 int cc;
179 QList<QLayoutStruct> rowData;
180 QList<QLayoutStruct> colData;
181 QList<QLayoutStruct> *hfwData;
182 QList<int> rStretch;
183 QList<int> cStretch;
184 QList<int> rMinHeights;
185 QList<int> cMinWidths;
186 QList<QGridBox *> things;
187
188 int hfw_width;
189 int hfw_height;
190 int hfw_minheight;
191 int nextR;
192 int nextC;
193
194 int horizontalSpacing;
195 int verticalSpacing;
196 int leftMargin;
197 int topMargin;
198 int rightMargin;
199 int bottomMargin;
200
201 uint hReversed : 1;
202 uint vReversed : 1;
203 uint needRecalc : 1;
204 uint has_hfw : 1;
205 uint addVertical : 1;
206};
207
208void QGridLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *bottom) const
209{
210 int l = leftMargin;
211 int t = topMargin;
212 int r = rightMargin;
213 int b = bottomMargin;
214#ifdef Q_OS_MAC
215 int leftMost = INT_MAX;
216 int topMost = INT_MAX;
217 int rightMost = 0;
218 int bottomMost = 0;
219
220 QWidget *w = nullptr;
221 const int n = things.count();
222 for (int i = 0; i < n; ++i) {
223 QGridBox *box = things.at(i);
224 QLayoutItem *itm = box->item();
225 w = itm->widget();
226 if (w) {
227 bool visualHReversed = hReversed != (w->layoutDirection() == Qt::RightToLeft);
228 QRect lir = itm->geometry();
229 QRect wr = w->geometry();
230 if (box->col <= leftMost) {
231 if (box->col < leftMost) {
232 // we found an item even closer to the margin, discard.
233 leftMost = box->col;
234 if (visualHReversed)
235 r = rightMargin;
236 else
237 l = leftMargin;
238 }
239 if (visualHReversed) {
240 r = qMax(r, wr.right() - lir.right());
241 } else {
242 l = qMax(l, lir.left() - wr.left());
243 }
244 }
245 if (box->row <= topMost) {
246 if (box->row < topMost) {
247 // we found an item even closer to the margin, discard.
248 topMost = box->row;
249 if (vReversed)
250 b = bottomMargin;
251 else
252 t = topMargin;
253 }
254 if (vReversed)
255 b = qMax(b, wr.bottom() - lir.bottom());
256 else
257 t = qMax(t, lir.top() - wr.top());
258 }
259 if (box->toCol(cc) >= rightMost) {
260 if (box->toCol(cc) > rightMost) {
261 // we found an item even closer to the margin, discard.
262 rightMost = box->toCol(cc);
263 if (visualHReversed)
264 l = leftMargin;
265 else
266 r = rightMargin;
267 }
268 if (visualHReversed) {
269 l = qMax(l, lir.left() - wr.left());
270 } else {
271 r = qMax(r, wr.right() - lir.right());
272 }
273
274 }
275 if (box->toRow(rr) >= bottomMost) {
276 if (box->toRow(rr) > bottomMost) {
277 // we found an item even closer to the margin, discard.
278 bottomMost = box->toRow(rr);
279 if (vReversed)
280 t = topMargin;
281 else
282 b = bottomMargin;
283 }
284 if (vReversed)
285 t = qMax(t, lir.top() - wr.top());
286 else
287 b = qMax(b, wr.bottom() - lir.bottom());
288 }
289 }
290 }
291
292#endif
293 if (left)
294 *left = l;
295 if (top)
296 *top = t;
297 if (right)
298 *right = r;
299 if (bottom)
300 *bottom = b;
301}
302
304{
305 addVertical = false;
306 setDirty();
307 rr = cc = 0;
308 nextR = nextC = 0;
309 hfwData = nullptr;
310 hReversed = false;
311 vReversed = false;
312 horizontalSpacing = -1;
313 verticalSpacing = -1;
314}
315
316#if 0
317QGridLayoutPrivate::QGridLayoutPrivate(int nRows, int nCols)
318 : rowData(0), colData(0)
319{
320 init();
321 if (nRows < 0) {
322 nRows = 1;
323 addVertical = false;
324 }
325 if (nCols < 0) {
326 nCols = 1;
327 addVertical = true;
328 }
329 setSize(nRows, nCols);
330}
331#endif
332
334{
335 while (!things.isEmpty())
336 delete things.takeFirst();
337 delete hfwData;
338}
339
340bool QGridLayoutPrivate::hasHeightForWidth(int hSpacing, int vSpacing)
341{
342 setupLayoutData(hSpacing, vSpacing);
343 return has_hfw;
344}
345
346/*
347 Assumes that setupLayoutData() has been called, and that
348 qGeomCalc() has filled in colData with appropriate values.
349*/
350void QGridLayoutPrivate::recalcHFW(int w)
351{
352 /*
353 Go through all children, using colData and heightForWidth()
354 and put the results in hfwData.
355 */
356 if (!hfwData)
357 hfwData = new QList<QLayoutStruct>(rr);
358 setupHfwLayoutData();
359 QList<QLayoutStruct> &rData = *hfwData;
360
361 int h = 0;
362 int mh = 0;
363 for (int r = 0; r < rr; r++) {
364 int spacing = rData.at(r).spacing;
365 h += rData.at(r).sizeHint + spacing;
366 mh += rData.at(r).minimumSize + spacing;
367 }
368
369 hfw_width = w;
370 hfw_height = qMin(QLAYOUTSIZE_MAX, h);
371 hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh);
372}
373
374int QGridLayoutPrivate::heightForWidth(int w, int hSpacing, int vSpacing)
375{
376 setupLayoutData(hSpacing, vSpacing);
377 if (!has_hfw)
378 return -1;
379 int left, top, right, bottom;
380 effectiveMargins(&left, &top, &right, &bottom);
381
382 int hMargins = left + right;
383 if (w - hMargins != hfw_width) {
384 qGeomCalc(colData, 0, cc, 0, w - hMargins);
385 recalcHFW(w - hMargins);
386 }
387 return hfw_height + top + bottom;
388}
389
390int QGridLayoutPrivate::minimumHeightForWidth(int w, int hSpacing, int vSpacing)
391{
392 (void)heightForWidth(w, hSpacing, vSpacing);
393 if (!has_hfw)
394 return -1;
395 int top, bottom;
396 effectiveMargins(nullptr, &top, nullptr, &bottom);
397 return hfw_minheight + top + bottom;
398}
399
400QSize QGridLayoutPrivate::findSize(int QLayoutStruct::*size, int hSpacing, int vSpacing) const
401{
402 QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);
403 that->setupLayoutData(hSpacing, vSpacing);
404
405 int w = 0;
406 int h = 0;
407
408 for (int r = 0; r < rr; r++)
409 h += rowData.at(r).*size + rowData.at(r).spacing;
410 for (int c = 0; c < cc; c++)
411 w += colData.at(c).*size + colData.at(c).spacing;
412
415
416 return QSize(w, h);
417}
418
419Qt::Orientations QGridLayoutPrivate::expandingDirections(int hSpacing, int vSpacing) const
420{
421 QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);
422 that->setupLayoutData(hSpacing, vSpacing);
423 Qt::Orientations ret;
424
425 for (int r = 0; r < rr; r++) {
426 if (rowData.at(r).expansive) {
427 ret |= Qt::Vertical;
428 break;
429 }
430 }
431 for (int c = 0; c < cc; c++) {
432 if (colData.at(c).expansive) {
434 break;
435 }
436 }
437 return ret;
438}
439
440QSize QGridLayoutPrivate::sizeHint(int hSpacing, int vSpacing) const
441{
442 return findSize(&QLayoutStruct::sizeHint, hSpacing, vSpacing);
443}
444
445QSize QGridLayoutPrivate::maximumSize(int hSpacing, int vSpacing) const
446{
447 return findSize(&QLayoutStruct::maximumSize, hSpacing, vSpacing);
448}
449
450QSize QGridLayoutPrivate::minimumSize(int hSpacing, int vSpacing) const
451{
452 return findSize(&QLayoutStruct::minimumSize, hSpacing, vSpacing);
453}
454
455void QGridLayoutPrivate::setSize(int r, int c)
456{
457 if ((int)rowData.size() < r) {
458 int newR = qMax(r, rr * 2);
459 rowData.resize(newR);
460 rStretch.resize(newR);
461 rMinHeights.resize(newR);
462 for (int i = rr; i < newR; i++) {
463 rowData[i].init();
464 rowData[i].maximumSize = 0;
465 rowData[i].pos = 0;
466 rowData[i].size = 0;
467 rStretch[i] = 0;
468 rMinHeights[i] = 0;
469 }
470 }
471 if ((int)colData.size() < c) {
472 int newC = qMax(c, cc * 2);
473 colData.resize(newC);
474 cStretch.resize(newC);
475 cMinWidths.resize(newC);
476 for (int i = cc; i < newC; i++) {
477 colData[i].init();
478 colData[i].maximumSize = 0;
479 colData[i].pos = 0;
480 colData[i].size = 0;
481 cStretch[i] = 0;
482 cMinWidths[i] = 0;
483 }
484 }
485
486 if (hfwData && (int)hfwData->size() < r) {
487 delete hfwData;
488 hfwData = nullptr;
489 hfw_width = -1;
490 }
491 rr = r;
492 cc = c;
493}
494
495void QGridLayoutPrivate::setNextPosAfter(int row, int col)
496{
497 if (addVertical) {
498 if (col > nextC || (col == nextC && row >= nextR)) {
499 nextR = row + 1;
500 nextC = col;
501 if (nextR >= rr) {
502 nextR = 0;
503 nextC++;
504 }
505 }
506 } else {
507 if (row > nextR || (row == nextR && col >= nextC)) {
508 nextR = row;
509 nextC = col + 1;
510 if (nextC >= cc) {
511 nextC = 0;
512 nextR++;
513 }
514 }
515 }
516}
517
519{
520 expand(row + 1, col + 1);
521 box->row = box->torow = row;
522 box->col = box->tocol = col;
523 things.append(box);
524 setDirty();
525 setNextPosAfter(row, col);
526}
527
528void QGridLayoutPrivate::add(QGridBox *box, int row1, int row2, int col1, int col2)
529{
530 if (Q_UNLIKELY(row2 >= 0 && row2 < row1))
531 qWarning("QGridLayout: Multi-cell fromRow greater than toRow");
532 if (Q_UNLIKELY(col2 >= 0 && col2 < col1))
533 qWarning("QGridLayout: Multi-cell fromCol greater than toCol");
534 if (row1 == row2 && col1 == col2) {
535 add(box, row1, col1);
536 return;
537 }
538 expand(qMax(row1, row2) + 1, qMax(col1, col2) + 1);
539 box->row = row1;
540 box->col = col1;
541
542 box->torow = row2;
543 box->tocol = col2;
544
545 things.append(box);
546 setDirty();
547 if (col2 < 0)
548 col2 = cc - 1;
549
550 setNextPosAfter(row2, col2);
551}
552
553void QGridLayoutPrivate::addData(QGridBox *box, const QGridLayoutSizeTriple &sizes, bool r, bool c)
554{
555 const QWidget *widget = box->item()->widget();
556
557 if (box->isEmpty() && widget)
558 return;
559
560 if (c) {
561 QLayoutStruct *data = &colData[box->col];
562 if (!cStretch.at(box->col))
563 data->stretch = qMax(data->stretch, box->hStretch());
564 data->sizeHint = qMax(sizes.hint.width(), data->sizeHint);
565 data->minimumSize = qMax(sizes.minS.width(), data->minimumSize);
566
567 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.width(),
568 box->expandingDirections() & Qt::Horizontal, box->isEmpty());
569 }
570 if (r) {
571 QLayoutStruct *data = &rowData[box->row];
572 if (!rStretch.at(box->row))
573 data->stretch = qMax(data->stretch, box->vStretch());
574 data->sizeHint = qMax(sizes.hint.height(), data->sizeHint);
575 data->minimumSize = qMax(sizes.minS.height(), data->minimumSize);
576
577 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.height(),
578 box->expandingDirections() & Qt::Vertical, box->isEmpty());
579 }
580}
581
582static void initEmptyMultiBox(QList<QLayoutStruct> &chain, int start, int end)
583{
584 for (int i = start; i <= end; i++) {
585 QLayoutStruct *data = &chain[i];
586 if (data->empty && data->maximumSize == 0) // truly empty box
587 data->maximumSize = QWIDGETSIZE_MAX;
588 data->empty = false;
589 }
590}
591
592static void distributeMultiBox(QList<QLayoutStruct> &chain, int start, int end, int minSize,
593 int sizeHint, QList<int> &stretchArray, int stretch)
594{
595 int i;
596 int w = 0;
597 int wh = 0;
598 int max = 0;
599
600 for (i = start; i <= end; i++) {
601 QLayoutStruct *data = &chain[i];
602 w += data->minimumSize;
603 wh += data->sizeHint;
604 max += data->maximumSize;
605 if (stretchArray.at(i) == 0)
606 data->stretch = qMax(data->stretch, stretch);
607
608 if (i != end) {
609 int spacing = data->spacing;
610 w += spacing;
611 wh += spacing;
612 max += spacing;
613 }
614 }
615
616 if (max < minSize) { // implies w < minSize
617 /*
618 We must increase the maximum size of at least one of the
619 items. qGeomCalc() will put the extra space in between the
620 items. We must recover that extra space and put it
621 somewhere. It does not really matter where, since the user
622 can always specify stretch factors and avoid this code.
623 */
624 qGeomCalc(chain, start, end - start + 1, 0, minSize);
625 int pos = 0;
626 for (i = start; i <= end; i++) {
627 QLayoutStruct *data = &chain[i];
628 int nextPos = (i == end) ? minSize : chain.at(i + 1).pos;
629 int realSize = nextPos - pos;
630 if (i != end)
631 realSize -= data->spacing;
632 if (data->minimumSize < realSize)
633 data->minimumSize = realSize;
634 if (data->maximumSize < data->minimumSize)
635 data->maximumSize = data->minimumSize;
636 pos = nextPos;
637 }
638 } else if (w < minSize) {
639 qGeomCalc(chain, start, end - start + 1, 0, minSize);
640 for (i = start; i <= end; i++) {
641 QLayoutStruct *data = &chain[i];
642 if (data->minimumSize < data->size)
643 data->minimumSize = data->size;
644 }
645 }
646
647 if (wh < sizeHint) {
648 qGeomCalc(chain, start, end - start + 1, 0, sizeHint);
649 for (i = start; i <= end; i++) {
650 QLayoutStruct *data = &chain[i];
651 if (data->sizeHint < data->size)
652 data->sizeHint = data->size;
653 }
654 }
655}
656
657static QGridBox *&gridAt(QGridBox *grid[], int r, int c, int cc,
658 Qt::Orientation orientation = Qt::Vertical)
659{
660 if (orientation == Qt::Horizontal)
661 qSwap(r, c);
662 return grid[(r * cc) + c];
663}
664
665void QGridLayoutPrivate::setupSpacings(QList<QLayoutStruct> &chain, QGridBox *grid[],
666 int fixedSpacing, Qt::Orientation orientation)
667{
668 Q_Q(QGridLayout);
669 int numRows = rr; // or columns if orientation is horizontal
670 int numColumns = cc; // or rows if orientation is horizontal
671
672 if (orientation == Qt::Horizontal) {
673 qSwap(numRows, numColumns);
674 }
675
676 QStyle *style = nullptr;
677 if (fixedSpacing < 0) {
678 if (QWidget *parentWidget = q->parentWidget())
679 style = parentWidget->style();
680 }
681
682 for (int c = 0; c < numColumns; ++c) {
683 QGridBox *previousBox = nullptr;
684 int previousRow = -1; // previous *non-empty* row
685
686 for (int r = 0; r < numRows; ++r) {
687 if (chain.at(r).empty)
688 continue;
689
690 QGridBox *box = gridAt(grid, r, c, cc, orientation);
691 if (previousRow != -1 && (!box || previousBox != box)) {
692 int spacing = fixedSpacing;
693 if (spacing < 0) {
694 QSizePolicy::ControlTypes controlTypes1 = QSizePolicy::DefaultType;
695 QSizePolicy::ControlTypes controlTypes2 = QSizePolicy::DefaultType;
696 if (previousBox)
697 controlTypes1 = previousBox->item()->controlTypes();
698 if (box)
699 controlTypes2 = box->item()->controlTypes();
700
701 if ((orientation == Qt::Horizontal && hReversed)
702 || (orientation == Qt::Vertical && vReversed))
703 qSwap(controlTypes1, controlTypes2);
704
705 if (style)
706 spacing = style->combinedLayoutSpacing(controlTypes1, controlTypes2,
707 orientation, nullptr, q->parentWidget());
708 } else {
709 if (orientation == Qt::Vertical) {
710 QGridBox *sibling = vReversed ? previousBox : box;
711 if (sibling) {
712 if (sibling->item()->isEmpty()) {
713 spacing = 0;
714 } else {
715 QWidget *wid = sibling->item()->widget();
716 if (wid)
717 spacing = qMax(spacing, sibling->item()->geometry().top() - wid->geometry().top());
718 }
719 }
720 }
721 }
722
723 if (spacing > chain.at(previousRow).spacing)
724 chain[previousRow].spacing = spacing;
725 }
726
727 previousBox = box;
728 previousRow = r;
729 }
730 }
731}
732
733//#define QT_LAYOUT_DISABLE_CACHING
734
735void QGridLayoutPrivate::setupLayoutData(int hSpacing, int vSpacing)
736{
737 Q_Q(QGridLayout);
738
739#ifndef QT_LAYOUT_DISABLE_CACHING
740 if (!needRecalc)
741 return;
742#endif
743 has_hfw = false;
744 int i;
745
746 for (i = 0; i < rr; i++) {
747 rowData[i].init(rStretch.at(i), rMinHeights.at(i));
748 rowData[i].maximumSize = rStretch.at(i) ? QLAYOUTSIZE_MAX : rMinHeights.at(i);
749 }
750 for (i = 0; i < cc; i++) {
751 colData[i].init(cStretch.at(i), cMinWidths.at(i));
752 colData[i].maximumSize = cStretch.at(i) ? QLAYOUTSIZE_MAX : cMinWidths.at(i);
753 }
754
755 int n = things.size();
756 QVarLengthArray<QGridLayoutSizeTriple> sizes(n);
757
758 bool has_multi = false;
759
760 /*
761 Grid of items. We use it to determine which items are
762 adjacent to which and compute the spacings correctly.
763 */
764 QVarLengthArray<QGridBox *> grid(rr * cc);
765 memset(grid.data(), 0, rr * cc * sizeof(QGridBox *));
766
767 /*
768 Initialize 'sizes' and 'grid' data structures, and insert
769 non-spanning items to our row and column data structures.
770 */
771 for (i = 0; i < n; ++i) {
772 QGridBox * const box = things.at(i);
773 sizes[i].minS = box->minimumSize();
774 sizes[i].hint = box->sizeHint();
775 sizes[i].maxS = box->maximumSize();
776
777 if (box->hasHeightForWidth())
778 has_hfw = true;
779
780 if (box->row == box->toRow(rr)) {
781 addData(box, sizes[i], true, false);
782 } else {
783 initEmptyMultiBox(rowData, box->row, box->toRow(rr));
784 has_multi = true;
785 }
786
787 if (box->col == box->toCol(cc)) {
788 addData(box, sizes[i], false, true);
789 } else {
790 initEmptyMultiBox(colData, box->col, box->toCol(cc));
791 has_multi = true;
792 }
793
794 for (int r = box->row; r <= box->toRow(rr); ++r) {
795 for (int c = box->col; c <= box->toCol(cc); ++c) {
796 gridAt(grid.data(), r, c, cc) = box;
797 }
798 }
799 }
800
801 setupSpacings(colData, grid.data(), hSpacing, Qt::Horizontal);
802 setupSpacings(rowData, grid.data(), vSpacing, Qt::Vertical);
803
804 /*
805 Insert multicell items to our row and column data structures.
806 This must be done after the non-spanning items to obtain a
807 better distribution in distributeMultiBox().
808 */
809 if (has_multi) {
810 for (i = 0; i < n; ++i) {
811 QGridBox * const box = things.at(i);
812
813 if (box->row != box->toRow(rr))
814 distributeMultiBox(rowData, box->row, box->toRow(rr), sizes[i].minS.height(),
815 sizes[i].hint.height(), rStretch, box->vStretch());
816 if (box->col != box->toCol(cc))
817 distributeMultiBox(colData, box->col, box->toCol(cc), sizes[i].minS.width(),
818 sizes[i].hint.width(), cStretch, box->hStretch());
819 }
820 }
821
822 for (i = 0; i < rr; i++)
823 rowData[i].expansive = rowData.at(i).expansive || rowData.at(i).stretch > 0;
824 for (i = 0; i < cc; i++)
825 colData[i].expansive = colData.at(i).expansive || colData.at(i).stretch > 0;
826
827 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
828
829 needRecalc = false;
830}
831
832void QGridLayoutPrivate::addHfwData(QGridBox *box, int width)
833{
834 QList<QLayoutStruct> &rData = *hfwData;
835 if (box->hasHeightForWidth()) {
836 int hint = box->heightForWidth(width);
837 rData[box->row].sizeHint = qMax(hint, rData.at(box->row).sizeHint);
838 rData[box->row].minimumSize = qMax(hint, rData.at(box->row).minimumSize);
839 } else {
840 QSize hint = box->sizeHint();
841 QSize minS = box->minimumSize();
842 rData[box->row].sizeHint = qMax(hint.height(), rData.at(box->row).sizeHint);
843 rData[box->row].minimumSize = qMax(minS.height(), rData.at(box->row).minimumSize);
844 }
845}
846
847/*
848 Similar to setupLayoutData(), but uses heightForWidth(colData)
849 instead of sizeHint(). Assumes that setupLayoutData() and
850 qGeomCalc(colData) has been called.
851*/
852void QGridLayoutPrivate::setupHfwLayoutData()
853{
854 QList<QLayoutStruct> &rData = *hfwData;
855 for (int i = 0; i < rr; i++) {
856 rData[i] = rowData.at(i);
857 rData[i].minimumSize = rData[i].sizeHint = rMinHeights.at(i);
858 }
859
860 for (int pass = 0; pass < 2; ++pass) {
861 for (int i = 0; i < things.size(); ++i) {
862 QGridBox *box = things.at(i);
863 int r1 = box->row;
864 int c1 = box->col;
865 int r2 = box->toRow(rr);
866 int c2 = box->toCol(cc);
867 int w = colData.at(c2).pos + colData.at(c2).size - colData.at(c1).pos;
868
869 if (r1 == r2) {
870 if (pass == 0)
871 addHfwData(box, w);
872 } else {
873 if (pass == 0) {
874 initEmptyMultiBox(rData, r1, r2);
875 } else {
876 QSize hint = box->sizeHint();
877 QSize min = box->minimumSize();
878 if (box->hasHeightForWidth()) {
879 int hfwh = box->heightForWidth(w);
880 if (hfwh > hint.height())
881 hint.setHeight(hfwh);
882 if (hfwh > min.height())
883 min.setHeight(hfwh);
884 }
885 distributeMultiBox(rData, r1, r2, min.height(), hint.height(),
886 rStretch, box->vStretch());
887 }
888 }
889 }
890 }
891 for (int i = 0; i < rr; i++)
892 rData[i].expansive = rData.at(i).expansive || rData.at(i).stretch > 0;
893}
894
895void QGridLayoutPrivate::distribute(QRect r, int hSpacing, int vSpacing)
896{
897 Q_Q(QGridLayout);
898 bool visualHReversed = hReversed;
899 QWidget *parent = q->parentWidget();
900 if (parent && parent->isRightToLeft())
901 visualHReversed = !visualHReversed;
902
903 setupLayoutData(hSpacing, vSpacing);
904
905 int left, top, right, bottom;
906 effectiveMargins(&left, &top, &right, &bottom);
907 r.adjust(+left, +top, -right, -bottom);
908
909 qGeomCalc(colData, 0, cc, r.x(), r.width());
910 QList<QLayoutStruct> *rDataPtr;
911 if (has_hfw) {
912 recalcHFW(r.width());
913 qGeomCalc(*hfwData, 0, rr, r.y(), r.height());
914 rDataPtr = hfwData;
915 } else {
916 qGeomCalc(rowData, 0, rr, r.y(), r.height());
917 rDataPtr = &rowData;
918 }
919 QList<QLayoutStruct> &rData = *rDataPtr;
920 int i;
921
922 bool reverse = ((r.bottom() > rect.bottom()) || (r.bottom() == rect.bottom()
923 && ((r.right() > rect.right()) != visualHReversed)));
924 int n = things.size();
925 for (i = 0; i < n; ++i) {
926 QGridBox *box = things.at(reverse ? n-i-1 : i);
927 int r2 = box->toRow(rr);
928 int c2 = box->toCol(cc);
929
930 int x = colData.at(box->col).pos;
931 int y = rData.at(box->row).pos;
932 int x2p = colData.at(c2).pos + colData.at(c2).size; // x2+1
933 int y2p = rData.at(r2).pos + rData.at(r2).size; // y2+1
934 int w = x2p - x;
935 int h = y2p - y;
936
937 if (visualHReversed)
938 x = r.left() + r.right() - x - w + 1;
939 if (vReversed)
940 y = r.top() + r.bottom() - y - h + 1;
941
942 box->setGeometry(QRect(x, y, w, h));
943 }
944}
945
947{
948 if (row < 0 || row >= rr || col < 0 || col >= cc)
949 return QRect();
950
951 const QList<QLayoutStruct> *rDataPtr;
952 if (has_hfw && hfwData)
953 rDataPtr = hfwData;
954 else
955 rDataPtr = &rowData;
956 return QRect(colData.at(col).pos, rDataPtr->at(row).pos,
957 colData.at(col).size, rDataPtr->at(row).size);
958}
959
1051 : QLayout(*new QGridLayoutPrivate, nullptr, parent)
1052{
1053 Q_D(QGridLayout);
1054 d->expand(1, 1);
1055}
1056
1067{
1068 Q_D(QGridLayout);
1069 if (orient == Qt::Horizontal) {
1070 d->expand(1, n);
1071 d->addVertical = false;
1072 } else {
1073 d->expand(n,1);
1074 d->addVertical = true;
1075 }
1076}
1077
1078
1086{
1087 Q_D(QGridLayout);
1088 d->deleteAll();
1089}
1090
1103{
1104 Q_D(QGridLayout);
1105 d->horizontalSpacing = spacing;
1106 invalidate();
1107}
1108
1110{
1111 Q_D(const QGridLayout);
1112 if (d->horizontalSpacing >= 0) {
1113 return d->horizontalSpacing;
1114 } else {
1116 }
1117}
1118
1131{
1132 Q_D(QGridLayout);
1133 d->verticalSpacing = spacing;
1134 invalidate();
1135}
1136
1138{
1139 Q_D(const QGridLayout);
1140 if (d->verticalSpacing >= 0) {
1141 return d->verticalSpacing;
1142 } else {
1144 }
1145}
1146
1154{
1155 Q_D(QGridLayout);
1156 d->horizontalSpacing = d->verticalSpacing = spacing;
1157 invalidate();
1158}
1159
1167{
1168 int hSpacing = horizontalSpacing();
1169 if (hSpacing == verticalSpacing()) {
1170 return hSpacing;
1171 } else {
1172 return -1;
1173 }
1174}
1175
1180{
1181 Q_D(const QGridLayout);
1182 return d->numRows();
1183}
1184
1189{
1190 Q_D(const QGridLayout);
1191 return d->numCols();
1192}
1193
1198{
1199 Q_D(const QGridLayout);
1201 int left, top, right, bottom;
1202 d->effectiveMargins(&left, &top, &right, &bottom);
1203 result += QSize(left + right, top + bottom);
1204 return result;
1205}
1206
1211{
1212 Q_D(const QGridLayout);
1213 QSize result(d->minimumSize(horizontalSpacing(), verticalSpacing()));
1214 int left, top, right, bottom;
1215 d->effectiveMargins(&left, &top, &right, &bottom);
1216 result += QSize(left + right, top + bottom);
1217 return result;
1218}
1219
1224{
1225 Q_D(const QGridLayout);
1226
1227 QSize s = d->maximumSize(horizontalSpacing(), verticalSpacing());
1228 int left, top, right, bottom;
1229 d->effectiveMargins(&left, &top, &right, &bottom);
1230 s += QSize(left + right, top + bottom);
1231 s = s.boundedTo(QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX));
1233 s.setWidth(QLAYOUTSIZE_MAX);
1235 s.setHeight(QLAYOUTSIZE_MAX);
1236 return s;
1237}
1238
1243{
1244 return const_cast<QGridLayout*>(this)->d_func()->hasHeightForWidth(horizontalSpacing(), verticalSpacing());
1245}
1246
1251{
1252 Q_D(const QGridLayout);
1253 QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);
1255}
1256
1261{
1262 Q_D(const QGridLayout);
1263 QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);
1265}
1266
1271{
1272 Q_D(const QGridLayout);
1273 return d->count();
1274}
1275
1276
1281{
1282 Q_D(const QGridLayout);
1283 return d->itemAt(index);
1284}
1285
1295{
1296 Q_D(const QGridLayout);
1297 int n = d->things.size();
1298 for (int i = 0; i < n; ++i) {
1299 QGridBox *box = d->things.at(i);
1300 if (row >= box->row && row <= box->toRow(d->rr)
1301 && column >= box->col && column <= box->toCol(d->cc)) {
1302 return box->item();
1303 }
1304 }
1305 return nullptr;
1306}
1307
1312{
1313 Q_D(QGridLayout);
1314 return d->takeAt(index);
1315}
1316
1326void QGridLayout::getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const
1327{
1328 Q_D(const QGridLayout);
1329 d->getItemPosition(index, row, column, rowSpan, columnSpan);
1330}
1331
1332
1337{
1338 Q_D(QGridLayout);
1339 if (d->isDirty() || rect != geometry()) {
1341 d->distribute(cr, horizontalSpacing(), verticalSpacing());
1343 }
1344}
1345
1356{
1357 Q_D(const QGridLayout);
1358 return d->cellRect(row, column);
1359}
1360
1365{
1366 Q_D(QGridLayout);
1367 int r, c;
1368 d->getNextPos(r, c);
1369 addItem(item, r, c);
1370}
1371
1382void QGridLayout::addItem(QLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment)
1383{
1384 Q_D(QGridLayout);
1385 QGridBox *b = new QGridBox(item);
1386 b->setAlignment(alignment);
1387 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1388 invalidate();
1389}
1390
1400{
1401 Q_D(QGridLayout);
1402 if (!d->checkWidget(widget))
1403 return;
1404 if (Q_UNLIKELY(row < 0 || column < 0)) {
1405 qWarning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",
1406 widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(),
1408 return;
1409 }
1412 addItem(b, row, column, 1, 1, alignment);
1413}
1414
1427void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn,
1428 int rowSpan, int columnSpan, Qt::Alignment alignment)
1429{
1430 Q_D(QGridLayout);
1431 if (!d->checkWidget(widget))
1432 return;
1433 int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;
1434 int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;
1436 QGridBox *b = new QGridBox(this, widget);
1437 b->setAlignment(alignment);
1438 d->add(b, fromRow, toRow, fromColumn, toColumn);
1439 invalidate();
1440}
1441
1464{
1465 Q_D(QGridLayout);
1466 if (!d->checkLayout(layout))
1467 return;
1468 if (!adoptLayout(layout))
1469 return;
1470 QGridBox *b = new QGridBox(layout);
1471 b->setAlignment(alignment);
1472 d->add(b, row, column);
1473}
1474
1485 int rowSpan, int columnSpan, Qt::Alignment alignment)
1486{
1487 Q_D(QGridLayout);
1488 if (!d->checkLayout(layout))
1489 return;
1490 if (!adoptLayout(layout))
1491 return;
1492 QGridBox *b = new QGridBox(layout);
1493 b->setAlignment(alignment);
1494 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1495}
1496
1510void QGridLayout::setRowStretch(int row, int stretch)
1511{
1512 Q_D(QGridLayout);
1513 d->setRowStretch(row, stretch);
1514 invalidate();
1515}
1516
1523{
1524 Q_D(const QGridLayout);
1525 return d->rowStretch(row);
1526}
1527
1534{
1535 Q_D(const QGridLayout);
1536 return d->colStretch(column);
1537}
1538
1557{
1558 Q_D(QGridLayout);
1559 d->setColStretch(column, stretch);
1560 invalidate();
1561}
1562
1563
1564
1571{
1572 Q_D(QGridLayout);
1573 d->setRowMinimumHeight(row, minSize);
1574 invalidate();
1575}
1576
1583{
1584 Q_D(const QGridLayout);
1585 return d->rowSpacing(row);
1586}
1587
1594{
1595 Q_D(QGridLayout);
1596 d->setColumnMinimumWidth(column, minSize);
1597 invalidate();
1598}
1599
1606{
1607 Q_D(const QGridLayout);
1608 return d->colSpacing(column);
1609}
1610
1614Qt::Orientations QGridLayout::expandingDirections() const
1615{
1616 Q_D(const QGridLayout);
1617 return d->expandingDirections(horizontalSpacing(), verticalSpacing());
1618}
1619
1624{
1625 Q_D(QGridLayout);
1626 d->setReversed(corner == Qt::BottomLeftCorner || corner == Qt::BottomRightCorner,
1627 corner == Qt::TopRightCorner || corner == Qt::BottomRightCorner);
1628}
1629
1635{
1636 Q_D(const QGridLayout);
1637 if (d->horReversed()) {
1638 return d->verReversed() ? Qt::BottomRightCorner : Qt::TopRightCorner;
1639 } else {
1640 return d->verReversed() ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
1641 }
1642}
1643
1648{
1649 Q_D(QGridLayout);
1650 d->setDirty();
1652}
1653
1655
1656#include "moc_qgridlayout.cpp"
QSize sizeHint() const
Qt::Alignment alignment() const
void setAlignment(Qt::Alignment a)
int hStretch()
Qt::Orientations expandingDirections() const
void setGeometry(const QRect &r)
QSize maximumSize() const
QLayoutItem * takeItem()
QSize minimumSize() const
void setItem(QLayoutItem *newitem)
QGridBox(QLayoutItem *lit)
int vStretch()
bool isEmpty() const
QGridBox(const QLayout *l, QWidget *wid)
bool hasHeightForWidth() const
QLayoutItem * item()
int heightForWidth(int w) const
int colSpacing(int c) const
bool verReversed() const
void distribute(QRect rect, int hSpacing, int vSpacing)
QLayoutItem * replaceAt(int index, QLayoutItem *newitem) override
QRect cellRect(int row, int col) const
void setRowStretch(int r, int s)
void setRowMinimumHeight(int r, int s)
bool horReversed() const
void setReversed(bool r, bool c)
void getNextPos(int &row, int &col)
Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const
int numRows() const
int rowSpacing(int r) const
void add(QGridBox *, int row, int col)
void expand(int rows, int cols)
QLayoutItem * takeAt(int index)
QLayoutItem * itemAt(int index) const
QSize sizeHint(int hSpacing, int vSpacing) const
bool hasHeightForWidth(int hSpacing, int vSpacing)
bool isDirty() const
void setColStretch(int c, int s)
int colStretch(int c) const
int numCols() const
QSize minimumSize(int hSpacing, int vSpacing) const
int minimumHeightForWidth(int width, int hSpacing, int vSpacing)
int rowStretch(int r) const
void setColumnMinimumWidth(int c, int s)
int heightForWidth(int width, int hSpacing, int vSpacing)
void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const
QSize maximumSize(int hSpacing, int vSpacing) const
The QGridLayout class lays out widgets in a grid.
Definition qgridlayout.h:21
void setGeometry(const QRect &) override
\reimp
void setHorizontalSpacing(int spacing)
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qgridlayout.h:64
int horizontalSpacing() const
the spacing between widgets that are laid out side by side
int columnStretch(int column) const
Returns the stretch factor for column column.
void addLayout(QLayout *, int row, int column, Qt::Alignment=Qt::Alignment())
Places the layout at position (row, column) in the grid.
int columnMinimumWidth(int column) const
Returns the column spacing for column column.
int verticalSpacing() const
the spacing between widgets that are laid out on top of each other
void setRowMinimumHeight(int row, int minSize)
Sets the minimum height of row row to minSize pixels.
void setDefaultPositioning(int n, Qt::Orientation orient)
int count() const override
\reimp
~QGridLayout()
Destroys the grid layout.
void setColumnMinimumWidth(int column, int minSize)
Sets the minimum width of column column to minSize pixels.
void getItemPosition(int idx, int *row, int *column, int *rowSpan, int *columnSpan) const
Returns the position information of the item with the given index.
QSize maximumSize() const override
\reimp
Qt::Corner originCorner() const
Returns the corner that's used for the grid's origin, i.e.
bool hasHeightForWidth() const override
\reimp
void setSpacing(int spacing) override
This function sets both the vertical and horizontal spacing to spacing.
int rowStretch(int row) const
Returns the stretch factor for row row.
int heightForWidth(int) const override
\reimp
QLayoutItem * itemAt(int index) const override
\reimp
int rowCount() const
Returns the number of rows in this grid.
QGridLayout(QWidget *parent=nullptr)
Constructs a new QGridLayout with parent widget, parent.
void invalidate() override
\reimp
QLayoutItem * itemAtPosition(int row, int column) const
void addItem(QLayoutItem *item, int row, int column, int rowSpan=1, int columnSpan=1, Qt::Alignment=Qt::Alignment())
Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it accord...
Qt::Orientations expandingDirections() const override
\reimp
int rowMinimumHeight(int row) const
Returns the minimum width set for row row.
void setVerticalSpacing(int spacing)
void setRowStretch(int row, int stretch)
Sets the stretch factor of row row to stretch.
int columnCount() const
Returns the number of columns in this grid.
QSize minimumSize() const override
\reimp
QRect cellRect(int row, int column) const
Returns the geometry of the cell with row row and column column in the grid.
QLayoutItem * takeAt(int index) override
\reimp
void setOriginCorner(Qt::Corner)
Sets the grid's origin corner, i.e.
int spacing() const override
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwi...
int minimumHeightForWidth(int) const override
\reimp
QSize sizeHint() const override
\reimp
void setColumnStretch(int column, int stretch)
Sets the stretch factor of column column to stretch.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition qlayoutitem.h:25
virtual Qt::Orientations expandingDirections() const =0
Returns whether this layout item can make use of more space than sizeHint().
virtual QSize minimumSize() const =0
Implemented in subclasses to return the minimum size of this item.
virtual bool isEmpty() const =0
Implemented in subclasses to return whether this item is empty, i.e.
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 QSize maximumSize() const =0
Implemented in subclasses to return the maximum size of this item.
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.
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
Definition qlayout.cpp:148
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
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
T takeAt(qsizetype i)
Definition qlist.h:609
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 resize(qsizetype size)
Definition qlist.h:403
void append(parameter_type t)
Definition qlist.h:458
QObject * parent
Definition qobject.h:73
QString objectName
the name of this object
Definition qobject.h:107
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
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
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
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
rect
[4]
uint alignment
Combined button and popup list for selecting options.
constexpr const T & min(const T &a, const T &b)
Definition qnumeric.h:366
@ BottomLeftCorner
@ TopRightCorner
@ TopLeftCorner
@ BottomRightCorner
@ AlignHorizontal_Mask
Definition qnamespace.h:151
@ AlignVertical_Mask
Definition qnamespace.h:161
@ RightToLeft
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
#define Q_UNLIKELY(x)
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
static void initEmptyMultiBox(QList< QLayoutStruct > &chain, int start, int end)
static void distributeMultiBox(QList< QLayoutStruct > &chain, int start, int end, int minSize, int sizeHint, QList< int > &stretchArray, int stretch)
static QGridBox *& gridAt(QGridBox *grid[], int r, int c, int cc, Qt::Orientation orientation=Qt::Vertical)
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
#define qWarning
Definition qlogging.h:166
return ret
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLboolean GLboolean GLboolean b
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]
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei width
GLint left
GLint GLint bottom
GLuint start
GLfloat n
GLsizei const GLint * box
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLuint64EXT * result
[6]
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
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
unsigned int uint
Definition qtypes.h:34
#define QWIDGETSIZE_MAX
Definition qwidget.h:917
const char className[16]
[1]
Definition qwizard.cpp:100
obj metaObject() -> className()
QObject::connect nullptr
QVBoxLayout * layout
MyCustomStruct c2
QRect r1(100, 200, 11, 16)
[0]
QRect r2(QPoint(100, 200), QSize(11, 16))
QGraphicsItem * item