57 QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
59 setContentsMargins(margin, margin, margin, margin);
63 m_hSpace(hSpacing), m_vSpace(vSpacing)
65 setContentsMargins(margin, margin, margin, margin);
84 itemList.append(item);
99 return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
112 return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
122 return itemList.size();
128 return itemList.value(
index);
135 return itemList.takeAt(
index);
160 int height = doLayout(QRect(0, 0, width, 0),
true);
170 QLayout::setGeometry(rect);
171 doLayout(rect,
false);
184 for (
const QLayoutItem* item : qAsConst(itemList))
185 size = size.expandedTo(item->minimumSize());
187 const QMargins margins = contentsMargins();
188 size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
196FlowLayout::doLayout(
const QRect& rect,
bool testOnly)
const
198 int left, top, right, bottom;
199 getContentsMargins(&left, &top, &right, &bottom);
200 QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
201 int x = effectiveRect.x();
202 int y = effectiveRect.y();
207 for (QLayoutItem* item : qAsConst(itemList))
209 const QWidget* wid = item->widget();
212 spaceX = wid->style()->layoutSpacing(
213 QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
216 spaceY = wid->style()->layoutSpacing(
217 QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
220 int nextX =
x + item->sizeHint().width() + spaceX;
221 if (nextX - spaceX > effectiveRect.right() && lineHeight > 0)
223 x = effectiveRect.x();
224 y = y + lineHeight + spaceY;
225 nextX =
x + item->sizeHint().width() + spaceX;
230 item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
233 lineHeight = qMax(lineHeight, item->sizeHint().height());
235 return y + lineHeight - rect.y() + bottom;
241FlowLayout::smartSpacing(QStyle::PixelMetric pm)
const
243 QObject* parent = this->parent();
248 else if (parent->isWidgetType())
250 QWidget* pw =
static_cast<QWidget*
>(parent);
251 return pw->style()->pixelMetric(pm,
nullptr, pw);
255 return static_cast<QLayout*
>(parent)->spacing();
void addItem(QLayoutItem *item) override
[2]
Qt::Orientations expandingDirections() const override
[5]
QSize sizeHint() const override
int count() const override
[4]
int heightForWidth(int) const override
bool hasHeightForWidth() const override
[6]
FlowLayout(QWidget *parent, int margin=-1, int hSpacing=-1, int vSpacing=-1)
[1]
QLayoutItem * itemAt(int index) const override
int horizontalSpacing() const
[3]
int verticalSpacing() const
QLayoutItem * takeAt(int index) override
void setGeometry(const QRect &rect) override
[7]
QSize minimumSize() const override
This file offers overloads of toIce() and fromIce() functions for STL container types.