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