Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickflexboxlayout.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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// Qt-Security score:significant reason:default
4
5#include <QtQuickLayouts/private/qquickflexboxlayout_p.h>
6#include <QtQuickLayouts/private/qquickflexboxlayoutengine_p.h>
7#include <QtQml/qqmlinfo.h>
8
9/*!
10 \qmltype FlexboxLayout
11 //! \nativetype QQuickFlexboxLayout
12 \inherits Item
13 \inqmlmodule QtQuick.Layouts
14 \ingroup layouts
15 \since 6.10
16 \preliminary
17 \brief The FlexboxLayout QML construct provides a flex layout for the
18 quick items.
19
20 The FlexboxLayout enables to layout the quick items in a flexible way as
21 similar to that of
22 \l {https://www.w3.org/TR/css-flexbox-1/}{CSS Flexible Box Layout}.
23 Internally Qt FlexboxLayout uses the \l{qtquick-attribution-yoga.html}{yoga engine}
24 to derive the geometry of
25 the flex items. The \l {https://www.yogalayout.dev/}{yoga library} is a
26 subset of the
27 \l {https://www.w3.org/TR/css-flexbox-1/}{CSS Flexible Box Layout}. Thus
28 FlexboxLayout can be limited to the feature as supported in the
29 \l {https://www.yogalayout.dev/}{yoga library}.
30
31 \note The FlexboxLayout adheres to yoga library version 2.0 for its
32 features.
33
34 The items within the FlexboxLayout can be configured with preferred,
35 minimum and maximum sizes through the existing layout attached properties.
36 For instance, if the item within the FlexboxLayout need to be stretched,
37 the layout attached property \l{Layout.fillWidth} or \l{Layout.fillHeight}
38 can be set.
39
40 Items in a FlexboxLayout support these attached properties:
41 \list
42 \li \l{FlexboxLayout.alignSelf}
43 \li \l{Layout.minimumWidth}
44 \li \l{Layout.minimumHeight}
45 \li \l{Layout.preferredWidth}
46 \li \l{Layout.preferredHeight}
47 \li \l{Layout.maximumWidth}
48 \li \l{Layout.maximumHeight}
49 \li \l{Layout.fillWidth}
50 \li \l{Layout.fillHeight}
51 \li \l{Layout.margins}
52 \li \l{Layout.leftMargin}
53 \li \l{Layout.rightMargin}
54 \li \l{Layout.topMargin}
55 \li \l{Layout.bottomMargin}
56 \endlist
57
58 Read more about attached properties \l{QML Object Attributes}{here}.
59 \sa ColumnLayout
60 \sa GridLayout
61 \sa RowLayout
62 \sa {QtQuick.Controls::StackView}{StackView}
63 \sa {Qt Quick Layouts Overview}
64
65 To be able to use this type more efficiently, it is recommended that you
66 understand the general mechanism of the Qt Quick Layouts module. Refer to
67 \l{Qt Quick Layouts Overview} for more information.
68
69 \section1 Example Usage
70
71 The following snippet shows the minimalistic example of using QML
72 FlexboxLayout to arrange the rectangle items in more flexible way
73
74 \snippet layouts/simpleFlexboxLayout.qml layout-definition
75*/
76
77QT_BEGIN_NAMESPACE
78
79class QQuickFlexboxLayoutPrivate : public QQuickLayoutPrivate
80{
81 Q_DECLARE_PUBLIC(QQuickFlexboxLayout)
82
83public:
84 QQuickFlexboxLayoutPrivate() : QQuickLayoutPrivate() {}
85 const QQuickFlexboxLayoutEngine& getFlexEngine() const { return m_flexEngine; }
86
87private:
88 QQuickFlexboxLayoutEngine m_flexEngine;
89 QQuickFlexboxLayout::FlexboxDirection m_direction = QQuickFlexboxLayout::Row;
90 QQuickFlexboxLayout::FlexboxWrap m_wrap = QQuickFlexboxLayout::NoWrap;
91 QQuickFlexboxLayout::FlexboxAlignment m_alignItems = QQuickFlexboxLayout::AlignStart;
92 // Align items within the layout in the multi-line containter (i.e. with
93 // wrap enabled) and its aligned to the cross axis of the flexbox layout
94 QQuickFlexboxLayout::FlexboxAlignment m_alignContent = QQuickFlexboxLayout::AlignStretch;
95 // Align content item in the multi-line containter and its aligned to the
96 // main axis of the flexbox layout
97 QQuickFlexboxLayout::FlexboxJustify m_justifyContent = QQuickFlexboxLayout::JustifyStart;
98 qreal m_gap = 0.;
99 qreal m_rowGap = 0.;
100 qreal m_columnGap = 0.;
101 std::bitset<QQuickFlexboxLayout::GapMax> m_gapBitSet;
102};
103
104static QQuickFlexboxLayoutAttached *attachedFlexboxLayoutObject(QQuickItem *item, bool create = false)
105{
106 return static_cast<QQuickFlexboxLayoutAttached*>(
107 qmlAttachedPropertiesObject<QQuickFlexboxLayout>(item, create));
108}
109
110QQuickFlexboxLayout::QQuickFlexboxLayout(QQuickItem *parent) :
111 QQuickLayout(*new QQuickFlexboxLayoutPrivate, parent)
112{
113 Q_D(QQuickFlexboxLayout);
114 d->m_flexEngine.setFlexboxParentItem(new QQuickFlexboxLayoutItem(this));
115}
116
117QQuickFlexboxLayout::~QQuickFlexboxLayout()
118{
119 Q_D(QQuickFlexboxLayout);
120 d->m_flexEngine.clearItems();
121}
122
123/*!
124 \qmlproperty enumeration FlexboxLayout::direction
125
126 This property holds the item layout direction within the flex box layout
127 and it defines the
128 \l {https://www.w3.org/TR/css-flexbox-1/#box-model}{main-axis}.
129
130 Possible values:
131
132 \value FlexboxLayout.Row (default) Items are laid out from
133 left to right.
134 \value FlexboxLayout.RowReversed Items are laid out from right to
135 left.
136 \value FlexboxLayout.Column Items are laid out from top to
137 bottom.
138 \value FlexboxLayout.ColumnReversed Items are laid out from bottom to
139 top.
140
141 The default value is \c FlexboxLayout.Row.
142*/
143QQuickFlexboxLayout::FlexboxDirection QQuickFlexboxLayout::direction() const
144{
145 Q_D(const QQuickFlexboxLayout);
146 return d->m_direction;
147}
148
149void QQuickFlexboxLayout::setDirection(QQuickFlexboxLayout::FlexboxDirection direction)
150{
151 Q_D(QQuickFlexboxLayout);
152 if (d->m_direction == direction)
153 return;
154 d->m_direction = direction;
155 invalidate();
156 emit directionChanged();
157}
158
159/*!
160 \qmlproperty enumeration FlexboxLayout::wrap
161
162 This property specifies that the items within the flex box layout can wrap
163 or not and it happens when the children overflow the size of the flex box
164 layout. If the items are wrapped, it will be placed in multiple lines
165 depending on overflow condition as stated. Each line takes up the
166 maximum size of the item along the
167 \l {https://www.w3.org/TR/css-flexbox-1/#box-model}{cross-axis}.
168
169 Possible values:
170
171 \value FlexboxLayout.Wrap Items are wrapped into multiple lines
172 within the flex box layout.
173 \value FlexboxLayout.NoWrap (default) Items are not wrapped and
174 laid out in single line within the
175 flex box layout.
176 \value FlexboxLayout.WrapReverse Items are wrapped into multiple lines
177 within the flex box layout in the
178 reverse direction.
179
180 The default value is \c FlexboxLayout.NoWrap.
181*/
182QQuickFlexboxLayout::FlexboxWrap QQuickFlexboxLayout::wrap() const
183{
184 Q_D(const QQuickFlexboxLayout);
185 return d->m_wrap;
186}
187
188void QQuickFlexboxLayout::setWrap(QQuickFlexboxLayout::FlexboxWrap wrapMode)
189{
190 Q_D(QQuickFlexboxLayout);
191 if (d->m_wrap == wrapMode)
192 return;
193 d->m_wrap = wrapMode;
194 invalidate();
195 emit wrapChanged();
196}
197
198/*!
199 \qmlproperty enumeration FlexboxLayout::alignItems
200
201 This property specifies the alignment of the items within the
202 \l {https://www.w3.org/TR/css-flexbox-1/#flex-lines}{flex lines} of the
203 flex box layout and its aligned along the
204 \l {https://www.w3.org/TR/css-flexbox-1/#box-model}{cross-axis}
205 (which is orthogonal to the main-axis, as defined by the property
206 \l {direction}). This property can be overridden by the
207 items within the flex box layout through the attached property
208 \l {FlexboxLayout.alignSelf}.
209
210 Possible values:
211
212 \value FlexboxLayout.AlignStart (default) Items are aligned to the
213 start of the flex box layout
214 cross-axis.
215 \value FlexboxLayout.AlignCenter Items are aligned along the center
216 of the flex box layout cross-axis.
217 \value FlexboxLayout.AlignEnd Items are aligned to the end of the
218 flex box layout cross-axis.
219
220 \note The alignments mentioned in possible values are only applicable for
221 the \l{alignItems} property
222
223 The default value is \c FlexboxLayout.AlignStart.
224*/
225QQuickFlexboxLayout::FlexboxAlignment QQuickFlexboxLayout::alignItems() const
226{
227 Q_D(const QQuickFlexboxLayout);
228 return d->m_alignItems;
229}
230
231void QQuickFlexboxLayout::setAlignItems(QQuickFlexboxLayout::FlexboxAlignment alignment)
232{
233 Q_D(QQuickFlexboxLayout);
234 if (alignment >= QQuickFlexboxLayout::AlignStretch || alignment <= QQuickFlexboxLayout::AlignAuto) {
235 qWarning("Not applicable for Flexbox layout container");
236 return;
237 }
238 if (d->m_alignItems == alignment)
239 return;
240 d->m_alignItems = alignment;
241 invalidate();
242 emit alignItemsChanged();
243}
244
245/*!
246 \qmlproperty enumeration FlexboxLayout::alignContent
247
248 This property specifies the distribution of the
249 \l {https://www.w3.org/TR/css-flexbox-1/#flex-lines}{flex lines} along the
250 \l {https://www.w3.org/TR/css-flexbox-1/#box-model}{cross-axis} of the
251 flex box layout.
252
253 Possible values:
254
255 \value FlexboxLayout.AlignStart Flex lines are aligned to
256 the start of the flex box layout.
257 \value FlexboxLayout.AlignCenter Flex lines are aligned along the
258 center of the flex box layout.
259 \value FlexboxLayout.AlignEnd Flex lines are aligned to the end
260 of the flex box layout.
261 \value FlexboxLayout.AlignStretch (default) Flex lines are stretched
262 according to the height of the flex
263 box layout.
264 \value FlexboxLayout.AlignSpaceBetween The spaces are evenly distributed
265 between the lines and no space
266 along the edge of the flex box
267 layout.
268 \value FlexboxLayout.AlignSpaceAround The spaces are evenly distributed
269 between the lines and half-size
270 space on the edges of the flex box
271 layout.
272 \value FlexboxLayout.AlignSpaceEvenly The spaces are evenly distributed
273 between the lines and the edges of
274 the flex box layout. Not supported
275 in Qt 6.10.
276
277 The default value is \c FlexboxLayout.AlignStart.
278*/
279QQuickFlexboxLayout::FlexboxAlignment QQuickFlexboxLayout::alignContent() const
280{
281 Q_D(const QQuickFlexboxLayout);
282 return d->m_alignContent;
283}
284
285void QQuickFlexboxLayout::setAlignContent(QQuickFlexboxLayout::FlexboxAlignment alignment)
286{
287 Q_D(QQuickFlexboxLayout);
288 if (alignment == QQuickFlexboxLayout::AlignSpaceEvenly) {
289 qmlWarning(this) << "Currently not supported for Flexbox layout container";
290 return;
291 }
292 if (d->m_alignContent == alignment)
293 return;
294 d->m_alignContent = alignment;
295 invalidate();
296 emit alignContentChanged();
297}
298
299/*!
300 \qmlproperty enumeration FlexboxLayout::justifyContent
301
302 This property specifies the distribution of the items along the
303 \l {https://www.w3.org/TR/css-flexbox-1/#box-model}{main-axis} of the
304 flex box layout.
305
306 Possible values:
307
308 \value FlexboxLayout.JustifyStart (default) Items are aligned to
309 the start of the flex box
310 layout.
311 \value FlexboxLayout.JustifyCenter Items are aligned along the
312 center of the flex box layout.
313 \value FlexboxLayout.JustifyEnd Items are aligned to the end of
314 the flex box layout.
315 \value FlexboxLayout.JustifySpaceBetween The spaces are evenly
316 distributed between the items
317 and no space along the edges
318 of the flex box layout.
319 \value FlexboxLayout.JustifySpaceAround The spaces are evenly
320 distributed between the items
321 and half-size space on the
322 edges of the flex box layout.
323 \value FlexboxLayout.JustiftSpaceEvenly The spaces are evenly
324 distributed between the items
325 and edges of the flex
326 box layout.
327
328 The default value is \c FlexboxLayout.JustifyStart.
329*/
330QQuickFlexboxLayout::FlexboxJustify QQuickFlexboxLayout::justifyContent() const
331{
332 Q_D(const QQuickFlexboxLayout);
333 return d->m_justifyContent;
334}
335
336void QQuickFlexboxLayout::setJustifyContent(QQuickFlexboxLayout::FlexboxJustify justifyContent)
337{
338 Q_D(QQuickFlexboxLayout);
339 if (d->m_justifyContent == justifyContent)
340 return;
341 d->m_justifyContent = justifyContent;
342 invalidate();
343 emit justifyContentChanged();
344}
345
346/*!
347 \qmlproperty real FlexboxLayout::gap
348
349 This property holds the amount of space that need to be applied
350 to the \l {FlexboxLayout} both along the
351 \l {https://www.w3.org/TR/css-align-3/#gaps}{inline axis and block axis}.
352
353 The default value is \c 0.
354*/
355qreal QQuickFlexboxLayout::gap() const
356{
357 Q_D(const QQuickFlexboxLayout);
358 return d->m_gap;
359}
360
361void QQuickFlexboxLayout::setGap(qreal gap)
362{
363 Q_D(QQuickFlexboxLayout);
364 if (d->m_gap == gap)
365 return;
366 d->m_gap = gap;
367 d->m_gapBitSet.set(GapAll);
368 invalidate();
369 emit gapChanged();
370 if (!isGapBitSet(GapRow))
371 emit rowGapChanged();
372 if (!isGapBitSet(GapColumn))
373 emit columnGapChanged();
374}
375
376void QQuickFlexboxLayout::resetGap()
377{
378 Q_D(QQuickFlexboxLayout);
379 d->m_gap = 0;
380 d->m_gapBitSet.reset(GapAll);
381 emit gapChanged();
382 if (!isGapBitSet(GapRow))
383 emit rowGapChanged();
384 if (!isGapBitSet(GapColumn))
385 emit columnGapChanged();
386}
387
388/*!
389 \qmlproperty real FlexboxLayout::rowGap
390
391 This property holds the amount of space that need to be applied to the
392 \l {FlexboxLayout} along the
393 \l {https://www.w3.org/TR/css-align-3/#gaps}{block axis}. Setting this
394 property overrides the \l{gap} value affecting the
395 \l {https://www.w3.org/TR/css-align-3/#gaps}{block axis}.
396
397 The default value is \c 0.
398*/
399qreal QQuickFlexboxLayout::rowGap() const
400{
401 Q_D(const QQuickFlexboxLayout);
402 if (!isGapBitSet(GapRow))
403 return d->m_gap;
404 return d->m_rowGap;
405}
406
407void QQuickFlexboxLayout::setRowGap(qreal gap)
408{
409 Q_D(QQuickFlexboxLayout);
410 if (d->m_rowGap == gap)
411 return;
412 d->m_rowGap = gap;
413 d->m_gapBitSet.set(QQuickFlexboxLayout::GapRow);
414 invalidate();
415 emit rowGapChanged();
416}
417
418void QQuickFlexboxLayout::resetRowGap()
419{
420 Q_D(QQuickFlexboxLayout);
421 d->m_rowGap = 0;
422 d->m_gapBitSet.reset(GapRow);
423 emit rowGapChanged();
424}
425
426/*!
427 \qmlproperty real FlexboxLayout::columnGap
428
429 This property holds the amount of space that need to be applied
430 to the \l {FlexboxLayout} along the
431 \l {https://www.w3.org/TR/css-align-3/#gaps}{inline axis}. Setting this
432 property override the \l{gap} value affecting the
433 \l {https://www.w3.org/TR/css-align-3/#gaps}{inline axis}.
434
435 The default value is \c 0.
436*/
437qreal QQuickFlexboxLayout::columnGap() const
438{
439 Q_D(const QQuickFlexboxLayout);
440 if (!isGapBitSet(GapColumn))
441 return d->m_gap;
442 return d->m_columnGap;
443}
444
445void QQuickFlexboxLayout::setColumnGap(qreal gap)
446{
447 Q_D(QQuickFlexboxLayout);
448 if (d->m_columnGap == gap)
449 return;
450 d->m_columnGap = gap;
451 d->m_gapBitSet.set(QQuickFlexboxLayout::GapColumn);
452 invalidate();
453 emit columnGapChanged();
454}
455
456void QQuickFlexboxLayout::resetColumnGap()
457{
458 Q_D(QQuickFlexboxLayout);
459 d->m_columnGap = 0;
460 d->m_gapBitSet.reset(GapColumn);
461 emit columnGapChanged();
462}
463
464void QQuickFlexboxLayout::updateLayoutItems()
465{
466 Q_D(QQuickFlexboxLayout);
467 // Clean all the items in the layout
468 d->m_flexEngine.clearItems();
469 // Update the parent item properties
470 if (auto *flexParentItem = d->m_flexEngine.getFlexboxParentItem()) {
471 flexParentItem->setFlexDirection(d->m_direction);
472 flexParentItem->setFlexWrap(d->m_wrap);
473 flexParentItem->setFlexAlignItemsProperty(d->m_alignItems);
474 flexParentItem->setFlexAlignContentProperty(d->m_alignContent);
475 flexParentItem->setFlexJustifyContentProperty(d->m_justifyContent);
476 if (isGapBitSet(QQuickFlexboxLayout::GapAll))
477 flexParentItem->setFlexGap(QQuickFlexboxLayout::GapAll, d->m_gap);
478 if (isGapBitSet(QQuickFlexboxLayout::GapRow))
479 flexParentItem->setFlexGap(QQuickFlexboxLayout::GapRow, d->m_rowGap);
480 if (isGapBitSet(QQuickFlexboxLayout::GapColumn))
481 flexParentItem->setFlexGap(QQuickFlexboxLayout::GapColumn, d->m_columnGap);
482 }
483
484 // Insert the items in the layout
485 const QList<QQuickItem *> items = childItems();
486 for (auto *childItem : items) {
487 Q_ASSERT(childItem);
488 checkAnchors(childItem);
489 if (shouldIgnoreItem(childItem))
490 continue;
491 // Create and set the attached properties of the flex item and add it as child
492 auto *flexLayoutItem = new QQuickFlexboxLayoutItem(childItem);
493 if (auto *flexItemAttachedProperties = attachedFlexboxLayoutObject(childItem))
494 flexLayoutItem->setFlexAlignSelfProperty(flexItemAttachedProperties->alignSelf());
495 d->m_flexEngine.insertItem(flexLayoutItem);
496 }
497}
498
499void QQuickFlexboxLayout::checkAnchors(QQuickItem *item) const
500{
501 QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors;
502 if (anchors && anchors->activeDirections())
503 qmlWarning(item) << "Detected anchors on an item that is managed by a layout. This is undefined behavior; use FlexboxLayout alignment properties instead.";
504}
505
506void QQuickFlexboxLayout::componentComplete()
507{
508 QQuickLayout::componentComplete();
509 ensureLayoutItemsUpdated(ApplySizeHints);
510 if (qobject_cast<QQuickLayout*>(parentItem()))
511 return;
512 rearrange(QSizeF(width(), height()));
513}
514
515void QQuickFlexboxLayout::itemVisibilityChanged(QQuickItem *item)
516{
517 if (!isReady())
518 return;
519 invalidate(item);
520}
521
522QSizeF QQuickFlexboxLayout::sizeHint(Qt::SizeHint whichSizeHint) const
523{
524 Q_D(const QQuickFlexboxLayout);
525 QSizeF sizeHint = d->m_flexEngine.sizeHint(whichSizeHint);
526 d->m_dirty = false;
527 return sizeHint;
528}
529
530QQuickFlexboxLayoutAttached *QQuickFlexboxLayout::qmlAttachedProperties(QObject *object)
531{
532 return new QQuickFlexboxLayoutAttached(object);
533}
534
535bool QQuickFlexboxLayout::isGapBitSet(QQuickFlexboxLayout::FlexboxGap gap) const
536{
537 Q_D(const QQuickFlexboxLayout);
538 if (gap < QQuickFlexboxLayout::GapRow || gap > QQuickFlexboxLayout::GapAll)
539 return false;
540 return d->m_gapBitSet[gap];
541}
542
543QQuickItem *QQuickFlexboxLayout::itemAt(int index) const
544{
545 const auto items = childItems();
546 for (QQuickItem *item : items) {
547 if (shouldIgnoreItem(item))
548 continue;
549 if (index == 0)
550 return item;
551 --index;
552 }
553 return nullptr;
554}
555
556int QQuickFlexboxLayout::itemCount() const
557{
558 int count = 0;
559 const auto items = childItems();
560 for (QQuickItem *item : items) {
561 if (shouldIgnoreItem(item))
562 continue;
563 ++count;
564 }
565 return count;
566}
567
568void QQuickFlexboxLayout::invalidate(QQuickItem *childItem)
569{
570 Q_D(QQuickFlexboxLayout);
571 d->m_flexEngine.invalidateItemSizeHint(childItem);
572 QQuickLayout::invalidate(this);
573 if (QQuickLayout *parentLayout = qobject_cast<QQuickLayout *>(parentItem()))
574 parentLayout->invalidate(this);
575}
576
577void QQuickFlexboxLayout::childItemsChanged()
578{
579 const int count = itemCount();
580 for (int i = 0; i < count; ++i) {
581 QQuickItem *child = itemAt(i);
582 checkAnchors(child);
583 }
584}
585
586void QQuickFlexboxLayout::rearrange(const QSizeF &newSize)
587{
588 Q_D(QQuickFlexboxLayout);
589 if (newSize.isNull() || !newSize.isValid())
590 return;
591 d->m_flexEngine.setGeometries(newSize);
592 QQuickLayout::rearrange(newSize);
593}
594
595void QQuickFlexboxLayout::itemSiblingOrderChanged(QQuickItem *)
596{
597 if (!isReady())
598 return;
599 invalidate();
600}
601
602QQuickFlexboxLayoutAttached::QQuickFlexboxLayoutAttached(QObject *object)
603{
604 auto item = qobject_cast<QQuickItem*>(object);
605 if (!item) {
606 qmlWarning(object) << "FlexboxLayout attached property must be attached to an object deriving from Item";
607 return;
608 }
609 setParent(object);
610 if (auto flexboxLayout = qobject_cast<QQuickFlexboxLayout*>(item->parentItem())) {
611 if (!flexboxLayout->isComponentComplete()) {
612 // Don't try to get the index if the FlexboxLayout itself hasn't
613 // loaded yet.
614 return;
615 }
616 // In case of lazy loading in loader, attachedProperties are created
617 // and updated for the object after adding the child object to the
618 // stack layout, which leads to entries with same index. Triggering
619 // childItemsChanged() resets to right index in the stack layout.
620 flexboxLayout->childItemsChanged();
621 }
622}
623
624/*!
625 \qmlattachedproperty enumeration FlexboxLayout::alignSelf
626
627 This attached property allows to align this item in the flex box layout
628 along the \l {https://www.w3.org/TR/css-flexbox-1/#box-model}{cross-axis}
629 and it overrides the parent flex box layout property
630 \l{alignItems}.
631
632 By default, the child item inherit the alignment from the parent and it can
633 override the parent flex box layout
634 \l{alignItems} property with the values
635 \c {FlexboxLayout.AlignStart}, \c {FlexboxLayout.AlignCenter}
636 and \c {FlexboxLayout.AlignEnd}.
637
638 The default value is \c {FlexboxLayout.AlignAuto}.
639*/
640QQuickFlexboxLayout::FlexboxAlignment QQuickFlexboxLayoutAttached::alignSelf() const
641{
642 return m_alignSelf;
643}
644
645void QQuickFlexboxLayoutAttached::setAlignSelf(QQuickFlexboxLayout::FlexboxAlignment alignment)
646{
647 if (m_alignSelf == alignment)
648 return;
649
650 m_alignSelf = alignment;
651 const auto *item = qobject_cast<QQuickItem*>(parent());
652 if (auto *flexLayout = qobject_cast<QQuickFlexboxLayout *>(item->parent())) {
653 auto *priv = dynamic_cast<QQuickFlexboxLayoutPrivate *>(QQuickLayoutPrivate::get(flexLayout));
654 auto &flexEngine = priv->getFlexEngine();
655 auto *item = qobject_cast<QQuickItem *>(parent());
656 if (auto *flexLayoutItem = flexEngine.findFlexboxLayoutItem(item)) {
657 flexLayoutItem->setFlexAlignSelfProperty(alignment);
658 flexLayout->invalidate();
659 }
660 }
661 emit alignSelfChanged();
662}
663
664QT_END_NAMESPACE
665
666#include "moc_qquickflexboxlayout_p.cpp"
static QQuickFlexboxLayoutAttached * attachedFlexboxLayoutObject(QQuickItem *item, bool create=false)