aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicklayouts/qquicklayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicklayouts/qquicklayout.cpp')
-rw-r--r--src/quicklayouts/qquicklayout.cpp74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/quicklayouts/qquicklayout.cpp b/src/quicklayouts/qquicklayout.cpp
index 74167db3e7..3699b3fbcf 100644
--- a/src/quicklayouts/qquicklayout.cpp
+++ b/src/quicklayouts/qquicklayout.cpp
@@ -88,7 +88,9 @@ QQuickLayoutAttached::QQuickLayoutAttached(QObject *parent)
m_isLeftMarginSet(false),
m_isTopMarginSet(false),
m_isRightMarginSet(false),
- m_isBottomMarginSet(false)
+ m_isBottomMarginSet(false),
+ m_horizontalStretch(-1),
+ m_verticalStretch(-1)
{
}
@@ -412,6 +414,76 @@ void QQuickLayoutAttached::setAlignment(Qt::Alignment align)
}
/*!
+ \qmlattachedproperty int Layout::horizontalStretchFactor
+
+ This property allows you to specify the horizontal stretch factor. By default, two identical
+ items arranged in a linear layout will have the same size, but if the first item has a
+ stretch factor of 1 and the second item has a stretch factor of 2, the first item will \e
+ aim to get 1/3 of the available space, and the second will \e aim to get 2/3 of the available
+ space. Note that, whether they become exactly 1/3 and 2/3 of the available space depends on
+ their size hints. This is because when e.g a horizontal layout is shown in its minimum width
+ all its child items will consequently also have their minimum width.
+
+ Likewise, when a horizontal layout has its preferred width, all child items will have their
+ preferred widths, and when a horizontal layout has its maximum width, all child items will have
+ their maximum widths. This strategy is applied regardless of what the individual stretch
+ factors are. As a consequence of this, stretch factors will only determine the growth rate of
+ child items \e between the preferredWidth and maximumWidth range.
+
+ The default value is \c -1, which means that no stretch factor is applied.
+
+ \note This requires that Layout::fillWidth is set to true
+
+ \sa verticalStretchFactor
+*/
+void QQuickLayoutAttached::setHorizontalStretchFactor(int factor)
+{
+ if (factor != m_horizontalStretch) {
+ m_horizontalStretch = factor;
+ if (QQuickLayout *layout = parentLayout()) {
+ layout->setStretchFactor(item(), factor, Qt::Horizontal);
+ invalidateItem();
+ }
+ emit horizontalStretchFactorChanged();
+ }
+}
+
+/*!
+ \qmlattachedproperty int Layout::verticalStretchFactor
+
+ This property allows you to specify the vertical stretch factor. By default, two identical
+ items arranged in a linear layout will have the same size, but if the first item has a
+ stretch factor of 1 and the second item has a stretch factor of 2, the first item will \e
+ aim to get 1/3 of the available space, and the second will \e aim to get 2/3 of the available
+ space. Note that, whether they become exactly 1/3 and 2/3 of the available space depends on
+ their size hints. This is because when e.g a vertical layout is shown in its minimum height
+ all its child items will consequently also have their minimum height.
+
+ Likewise, when a vertical layout has its preferred height, all child items will have their
+ preferred heights, and when a vertical layout has its maximum height, all child items will have
+ their maximum heights. This strategy is applied regardless of what the individual stretch
+ factors are. As a consequence of this, stretch factors will only determine the growth rate of
+ child items \e between the preferredHeight and maximumHeight range.
+
+ The default value is \c -1, which means that no stretch factor is applied.
+
+ \note This requires that Layout::fillHeight is set to true
+
+ \sa horizontalStretchFactor
+*/
+void QQuickLayoutAttached::setVerticalStretchFactor(int factor)
+{
+ if (factor != m_verticalStretch) {
+ m_verticalStretch = factor;
+ if (QQuickLayout *layout = parentLayout()) {
+ layout->setStretchFactor(item(), factor, Qt::Vertical);
+ invalidateItem();
+ }
+ emit verticalStretchFactorChanged();
+ }
+}
+
+/*!
\qmlattachedproperty real Layout::margins
Sets the margins outside of an item to all have the same value. The item