A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQLayout</id>
		<title>C++/Qt/QLayout - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQLayout"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QLayout&amp;action=history"/>
		<updated>2026-04-18T20:40:43Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QLayout&amp;diff=1112&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QLayout&amp;diff=1112&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QLayout&amp;diff=1113&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QLayout&amp;diff=1113&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:50Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==extends QLayout to create border layout==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef BORDERLAYOUT_H&lt;br /&gt;
#define BORDERLAYOUT_H&lt;br /&gt;
#include &amp;lt;QLayout&amp;gt;&lt;br /&gt;
#include &amp;lt;QRect&amp;gt;&lt;br /&gt;
#include &amp;lt;QWidgetItem&amp;gt;&lt;br /&gt;
class BorderLayout : public QLayout&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    enum Position { West, North, South, East, Center };&lt;br /&gt;
    BorderLayout(QWidget *parent, int margin = 0, int spacing = -1);&lt;br /&gt;
    BorderLayout(int spacing = -1);&lt;br /&gt;
    ~BorderLayout();&lt;br /&gt;
    void addItem(QLayoutItem *item);&lt;br /&gt;
    void addWidget(QWidget *widget, Position position);&lt;br /&gt;
    Qt::Orientations expandingDirections() const;&lt;br /&gt;
    bool hasHeightForWidth() const;&lt;br /&gt;
    int count() const;&lt;br /&gt;
    QLayoutItem *itemAt(int index) const;&lt;br /&gt;
    QSize minimumSize() const;&lt;br /&gt;
    void setGeometry(const QRect &amp;amp;rect);&lt;br /&gt;
    QSize sizeHint() const;&lt;br /&gt;
    QLayoutItem *takeAt(int index);&lt;br /&gt;
    void add(QLayoutItem *item, Position position);&lt;br /&gt;
private:&lt;br /&gt;
    struct ItemWrapper&lt;br /&gt;
    {&lt;br /&gt;
  ItemWrapper(QLayoutItem *i, Position p) {&lt;br /&gt;
      item = i;&lt;br /&gt;
      position = p;&lt;br /&gt;
  }&lt;br /&gt;
  QLayoutItem *item;&lt;br /&gt;
  Position position;&lt;br /&gt;
    };&lt;br /&gt;
    enum SizeType { MinimumSize, SizeHint };&lt;br /&gt;
    QSize calculateSize(SizeType sizeType) const;&lt;br /&gt;
    QList&amp;lt;ItemWrapper *&amp;gt; list;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;borderlayout.h&amp;quot;&lt;br /&gt;
BorderLayout::BorderLayout(QWidget *parent, int margin, int spacing)&lt;br /&gt;
    : QLayout(parent)&lt;br /&gt;
{&lt;br /&gt;
    setMargin(margin);&lt;br /&gt;
    setSpacing(spacing);&lt;br /&gt;
}&lt;br /&gt;
BorderLayout::BorderLayout(int spacing)&lt;br /&gt;
{&lt;br /&gt;
    setSpacing(spacing);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BorderLayout::~BorderLayout()&lt;br /&gt;
{&lt;br /&gt;
    QLayoutItem *l;&lt;br /&gt;
    while ((l = takeAt(0)))&lt;br /&gt;
        delete l;&lt;br /&gt;
}&lt;br /&gt;
void BorderLayout::addItem(QLayoutItem *item)&lt;br /&gt;
{&lt;br /&gt;
    add(item, West);&lt;br /&gt;
}&lt;br /&gt;
void BorderLayout::addWidget(QWidget *widget, Position position)&lt;br /&gt;
{&lt;br /&gt;
    add(new QWidgetItem(widget), position);&lt;br /&gt;
}&lt;br /&gt;
Qt::Orientations BorderLayout::expandingDirections() const&lt;br /&gt;
{&lt;br /&gt;
    return Qt::Horizontal | Qt::Vertical;&lt;br /&gt;
}&lt;br /&gt;
bool BorderLayout::hasHeightForWidth() const&lt;br /&gt;
{&lt;br /&gt;
    return false;&lt;br /&gt;
}&lt;br /&gt;
int BorderLayout::count() const&lt;br /&gt;
{&lt;br /&gt;
    return list.size();&lt;br /&gt;
}&lt;br /&gt;
QLayoutItem *BorderLayout::itemAt(int index) const&lt;br /&gt;
{&lt;br /&gt;
    ItemWrapper *wrapper = list.value(index);&lt;br /&gt;
    if (wrapper)&lt;br /&gt;
        return wrapper-&amp;gt;item;&lt;br /&gt;
    else&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
QSize BorderLayout::minimumSize() const&lt;br /&gt;
{&lt;br /&gt;
    return calculateSize(MinimumSize);&lt;br /&gt;
}&lt;br /&gt;
void BorderLayout::setGeometry(const QRect &amp;amp;rect)&lt;br /&gt;
{&lt;br /&gt;
    ItemWrapper *center = 0;&lt;br /&gt;
    int eastWidth = 0;&lt;br /&gt;
    int westWidth = 0;&lt;br /&gt;
    int northHeight = 0;&lt;br /&gt;
    int southHeight = 0;&lt;br /&gt;
    int centerHeight = 0;&lt;br /&gt;
    int i;&lt;br /&gt;
    QLayout::setGeometry(rect);&lt;br /&gt;
    for (i = 0; i &amp;lt; list.size(); ++i) {&lt;br /&gt;
        ItemWrapper *wrapper = list.at(i);&lt;br /&gt;
        QLayoutItem *item = wrapper-&amp;gt;item;&lt;br /&gt;
        Position position = wrapper-&amp;gt;position;&lt;br /&gt;
        if (position == North) {&lt;br /&gt;
            item-&amp;gt;setGeometry(QRect(rect.x(), northHeight, rect.width(),&lt;br /&gt;
                                    item-&amp;gt;sizeHint().height()));&lt;br /&gt;
            northHeight += item-&amp;gt;geometry().height() + spacing();&lt;br /&gt;
        } else if (position == South) {&lt;br /&gt;
            item-&amp;gt;setGeometry(QRect(item-&amp;gt;geometry().x(),&lt;br /&gt;
                                    item-&amp;gt;geometry().y(), rect.width(),&lt;br /&gt;
                                    item-&amp;gt;sizeHint().height()));&lt;br /&gt;
            southHeight += item-&amp;gt;geometry().height() + spacing();&lt;br /&gt;
            item-&amp;gt;setGeometry(QRect(rect.x(),&lt;br /&gt;
                              rect.y() + rect.height() - southHeight + spacing(),&lt;br /&gt;
                              item-&amp;gt;geometry().width(),&lt;br /&gt;
                              item-&amp;gt;geometry().height()));&lt;br /&gt;
        } else if (position == Center) {&lt;br /&gt;
            center = wrapper;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    centerHeight = rect.height() - northHeight - southHeight;&lt;br /&gt;
    for (i = 0; i &amp;lt; list.size(); ++i) {&lt;br /&gt;
        ItemWrapper *wrapper = list.at(i);&lt;br /&gt;
        QLayoutItem *item = wrapper-&amp;gt;item;&lt;br /&gt;
        Position position = wrapper-&amp;gt;position;&lt;br /&gt;
        if (position == West) {&lt;br /&gt;
            item-&amp;gt;setGeometry(QRect(rect.x() + westWidth, northHeight,&lt;br /&gt;
                                    item-&amp;gt;sizeHint().width(), centerHeight));&lt;br /&gt;
            westWidth += item-&amp;gt;geometry().width() + spacing();&lt;br /&gt;
        } else if (position == East) {&lt;br /&gt;
            item-&amp;gt;setGeometry(QRect(item-&amp;gt;geometry().x(), item-&amp;gt;geometry().y(),&lt;br /&gt;
                                    item-&amp;gt;sizeHint().width(), centerHeight));&lt;br /&gt;
            eastWidth += item-&amp;gt;geometry().width() + spacing();&lt;br /&gt;
            item-&amp;gt;setGeometry(QRect(&lt;br /&gt;
                              rect.x() + rect.width() - eastWidth + spacing(),&lt;br /&gt;
                              northHeight, item-&amp;gt;geometry().width(),&lt;br /&gt;
                              item-&amp;gt;geometry().height()));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (center)&lt;br /&gt;
        center-&amp;gt;item-&amp;gt;setGeometry(QRect(westWidth, northHeight,&lt;br /&gt;
                                        rect.width() - eastWidth - westWidth,&lt;br /&gt;
                                        centerHeight));&lt;br /&gt;
}&lt;br /&gt;
QSize BorderLayout::sizeHint() const&lt;br /&gt;
{&lt;br /&gt;
    return calculateSize(SizeHint);&lt;br /&gt;
}&lt;br /&gt;
QLayoutItem *BorderLayout::takeAt(int index)&lt;br /&gt;
{&lt;br /&gt;
    if (index &amp;gt;= 0 &amp;amp;&amp;amp; index &amp;lt; list.size()) {&lt;br /&gt;
        ItemWrapper *layoutStruct = list.takeAt(index);&lt;br /&gt;
        return layoutStruct-&amp;gt;item;&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
void BorderLayout::add(QLayoutItem *item, Position position)&lt;br /&gt;
{&lt;br /&gt;
    list.append(new ItemWrapper(item, position));&lt;br /&gt;
}&lt;br /&gt;
QSize BorderLayout::calculateSize(SizeType sizeType) const&lt;br /&gt;
{&lt;br /&gt;
    QSize totalSize;&lt;br /&gt;
    for (int i = 0; i &amp;lt; list.size(); ++i) {&lt;br /&gt;
        ItemWrapper *wrapper = list.at(i);&lt;br /&gt;
        Position position = wrapper-&amp;gt;position;&lt;br /&gt;
        QSize itemSize;&lt;br /&gt;
        if (sizeType == MinimumSize)&lt;br /&gt;
            itemSize = wrapper-&amp;gt;item-&amp;gt;minimumSize();&lt;br /&gt;
        else // (sizeType == SizeHint)&lt;br /&gt;
            itemSize = wrapper-&amp;gt;item-&amp;gt;sizeHint();&lt;br /&gt;
        if (position == North || position == South || position == Center)&lt;br /&gt;
            totalSize.rheight() += itemSize.height();&lt;br /&gt;
        if (position == West || position == East || position == Center)&lt;br /&gt;
            totalSize.rwidth() += itemSize.width();&lt;br /&gt;
    }&lt;br /&gt;
    return totalSize;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
QT_BEGIN_NAMESPACE&lt;br /&gt;
class QLabel;&lt;br /&gt;
QT_END_NAMESPACE&lt;br /&gt;
class Window : public QWidget&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    Window();&lt;br /&gt;
private:&lt;br /&gt;
    QLabel *createLabel(const QString &amp;amp;text);&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;borderlayout.h&amp;quot;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
Window::Window()&lt;br /&gt;
{&lt;br /&gt;
    QTextBrowser *centralWidget = new QTextBrowser;&lt;br /&gt;
    centralWidget-&amp;gt;setPlainText(tr(&amp;quot;Central widget&amp;quot;));&lt;br /&gt;
    BorderLayout *layout = new BorderLayout;&lt;br /&gt;
    layout-&amp;gt;addWidget(centralWidget, BorderLayout::Center);&lt;br /&gt;
    layout-&amp;gt;addWidget(createLabel(&amp;quot;North&amp;quot;), BorderLayout::North);&lt;br /&gt;
    layout-&amp;gt;addWidget(createLabel(&amp;quot;West&amp;quot;), BorderLayout::West);&lt;br /&gt;
    layout-&amp;gt;addWidget(createLabel(&amp;quot;East 1&amp;quot;), BorderLayout::East);&lt;br /&gt;
    layout-&amp;gt;addWidget(createLabel(&amp;quot;East 2&amp;quot;) , BorderLayout::East);&lt;br /&gt;
    layout-&amp;gt;addWidget(createLabel(&amp;quot;South&amp;quot;), BorderLayout::South);&lt;br /&gt;
    setLayout(layout);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Border Layout&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
QLabel *Window::createLabel(const QString &amp;amp;text)&lt;br /&gt;
{&lt;br /&gt;
    QLabel *label = new QLabel(text);&lt;br /&gt;
    label-&amp;gt;setFrameStyle(QFrame::Box | QFrame::Raised);&lt;br /&gt;
    return label;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    Window window;&lt;br /&gt;
    window.show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==extends QLayout to create flow layout==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef FLOWLAYOUT_H&lt;br /&gt;
#define FLOWLAYOUT_H&lt;br /&gt;
#include &amp;lt;QLayout&amp;gt;&lt;br /&gt;
#include &amp;lt;QRect&amp;gt;&lt;br /&gt;
#include &amp;lt;QWidgetItem&amp;gt;&lt;br /&gt;
class FlowLayout : public QLayout&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);&lt;br /&gt;
    FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);&lt;br /&gt;
    ~FlowLayout();&lt;br /&gt;
    void addItem(QLayoutItem *item);&lt;br /&gt;
    int horizontalSpacing() const;&lt;br /&gt;
    int verticalSpacing() const;&lt;br /&gt;
    Qt::Orientations expandingDirections() const;&lt;br /&gt;
    bool hasHeightForWidth() const;&lt;br /&gt;
    int heightForWidth(int) const;&lt;br /&gt;
    int count() const;&lt;br /&gt;
    QLayoutItem *itemAt(int index) const;&lt;br /&gt;
    QSize minimumSize() const;&lt;br /&gt;
    void setGeometry(const QRect &amp;amp;rect);&lt;br /&gt;
    QSize sizeHint() const;&lt;br /&gt;
    QLayoutItem *takeAt(int index);&lt;br /&gt;
private:&lt;br /&gt;
    int doLayout(const QRect &amp;amp;rect, bool testOnly) const;&lt;br /&gt;
    int smartSpacing(QStyle::PixelMetric pm) const;&lt;br /&gt;
    QList&amp;lt;QLayoutItem *&amp;gt; itemList;&lt;br /&gt;
    int m_hSpace;&lt;br /&gt;
    int m_vSpace;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;flowlayout.h&amp;quot;&lt;br /&gt;
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)&lt;br /&gt;
    : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)&lt;br /&gt;
{&lt;br /&gt;
    setContentsMargins(margin, margin, margin, margin);&lt;br /&gt;
}&lt;br /&gt;
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)&lt;br /&gt;
    : m_hSpace(hSpacing), m_vSpace(vSpacing)&lt;br /&gt;
{&lt;br /&gt;
    setContentsMargins(margin, margin, margin, margin);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
FlowLayout::~FlowLayout()&lt;br /&gt;
{&lt;br /&gt;
    QLayoutItem *item;&lt;br /&gt;
    while ((item = takeAt(0)))&lt;br /&gt;
        delete item;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void FlowLayout::addItem(QLayoutItem *item)&lt;br /&gt;
{&lt;br /&gt;
    itemList.append(item);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int FlowLayout::horizontalSpacing() const&lt;br /&gt;
{&lt;br /&gt;
    if (m_hSpace &amp;gt;= 0) {&lt;br /&gt;
        return m_hSpace;&lt;br /&gt;
    } else {&lt;br /&gt;
        return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
int FlowLayout::verticalSpacing() const&lt;br /&gt;
{&lt;br /&gt;
    if (m_vSpace &amp;gt;= 0) {&lt;br /&gt;
        return m_vSpace;&lt;br /&gt;
    } else {&lt;br /&gt;
        return smartSpacing(QStyle::PM_LayoutVerticalSpacing);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int FlowLayout::count() const&lt;br /&gt;
{&lt;br /&gt;
    return itemList.size();&lt;br /&gt;
}&lt;br /&gt;
QLayoutItem *FlowLayout::itemAt(int index) const&lt;br /&gt;
{&lt;br /&gt;
    return itemList.value(index);&lt;br /&gt;
}&lt;br /&gt;
QLayoutItem *FlowLayout::takeAt(int index)&lt;br /&gt;
{&lt;br /&gt;
    if (index &amp;gt;= 0 &amp;amp;&amp;amp; index &amp;lt; itemList.size())&lt;br /&gt;
        return itemList.takeAt(index);&lt;br /&gt;
    else&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Qt::Orientations FlowLayout::expandingDirections() const&lt;br /&gt;
{&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
bool FlowLayout::hasHeightForWidth() const&lt;br /&gt;
{&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
int FlowLayout::heightForWidth(int width) const&lt;br /&gt;
{&lt;br /&gt;
    int height = doLayout(QRect(0, 0, width, 0), true);&lt;br /&gt;
    return height;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void FlowLayout::setGeometry(const QRect &amp;amp;rect)&lt;br /&gt;
{&lt;br /&gt;
    QLayout::setGeometry(rect);&lt;br /&gt;
    doLayout(rect, false);&lt;br /&gt;
}&lt;br /&gt;
QSize FlowLayout::sizeHint() const&lt;br /&gt;
{&lt;br /&gt;
    return minimumSize();&lt;br /&gt;
}&lt;br /&gt;
QSize FlowLayout::minimumSize() const&lt;br /&gt;
{&lt;br /&gt;
    QSize size;&lt;br /&gt;
    QLayoutItem *item;&lt;br /&gt;
    foreach (item, itemList)&lt;br /&gt;
        size = size.expandedTo(item-&amp;gt;minimumSize());&lt;br /&gt;
    size += QSize(2*margin(), 2*margin());&lt;br /&gt;
    return size;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int FlowLayout::doLayout(const QRect &amp;amp;rect, bool testOnly) const&lt;br /&gt;
{&lt;br /&gt;
    int left, top, right, bottom;&lt;br /&gt;
    getContentsMargins(&amp;amp;left, &amp;amp;top, &amp;amp;right, &amp;amp;bottom);&lt;br /&gt;
    QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);&lt;br /&gt;
    int x = effectiveRect.x();&lt;br /&gt;
    int y = effectiveRect.y();&lt;br /&gt;
    int lineHeight = 0;&lt;br /&gt;
&lt;br /&gt;
    QLayoutItem *item;&lt;br /&gt;
    foreach (item, itemList) {&lt;br /&gt;
        QWidget *wid = item-&amp;gt;widget();&lt;br /&gt;
        int spaceX = horizontalSpacing();&lt;br /&gt;
        if (spaceX == -1)&lt;br /&gt;
            spaceX = wid-&amp;gt;style()-&amp;gt;layoutSpacing(&lt;br /&gt;
                QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);&lt;br /&gt;
        int spaceY = verticalSpacing();&lt;br /&gt;
        if (spaceY == -1)&lt;br /&gt;
            spaceY = wid-&amp;gt;style()-&amp;gt;layoutSpacing(&lt;br /&gt;
                QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);&lt;br /&gt;
&lt;br /&gt;
        int nextX = x + item-&amp;gt;sizeHint().width() + spaceX;&lt;br /&gt;
        if (nextX - spaceX &amp;gt; effectiveRect.right() &amp;amp;&amp;amp; lineHeight &amp;gt; 0) {&lt;br /&gt;
            x = effectiveRect.x();&lt;br /&gt;
            y = y + lineHeight + spaceY;&lt;br /&gt;
            nextX = x + item-&amp;gt;sizeHint().width() + spaceX;&lt;br /&gt;
            lineHeight = 0;&lt;br /&gt;
        }&lt;br /&gt;
        if (!testOnly)&lt;br /&gt;
            item-&amp;gt;setGeometry(QRect(QPoint(x, y), item-&amp;gt;sizeHint()));&lt;br /&gt;
        x = nextX;&lt;br /&gt;
        lineHeight = qMax(lineHeight, item-&amp;gt;sizeHint().height());&lt;br /&gt;
    }&lt;br /&gt;
    return y + lineHeight - rect.y() + bottom;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const&lt;br /&gt;
{&lt;br /&gt;
    QObject *parent = this-&amp;gt;parent();&lt;br /&gt;
    if (!parent) {&lt;br /&gt;
        return -1;&lt;br /&gt;
    } else if (parent-&amp;gt;isWidgetType()) {&lt;br /&gt;
        QWidget *pw = static_cast&amp;lt;QWidget *&amp;gt;(parent);&lt;br /&gt;
        return pw-&amp;gt;style()-&amp;gt;pixelMetric(pm, 0, pw);&lt;br /&gt;
    } else {&lt;br /&gt;
        return static_cast&amp;lt;QLayout *&amp;gt;(parent)-&amp;gt;spacing();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
QT_BEGIN_NAMESPACE&lt;br /&gt;
class QLabel;&lt;br /&gt;
QT_END_NAMESPACE&lt;br /&gt;
class Window : public QWidget&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    Window();&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;flowlayout.h&amp;quot;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
Window::Window()&lt;br /&gt;
{&lt;br /&gt;
    FlowLayout *flowLayout = new FlowLayout;&lt;br /&gt;
    flowLayout-&amp;gt;addWidget(new QPushButton(tr(&amp;quot;Short&amp;quot;)));&lt;br /&gt;
    flowLayout-&amp;gt;addWidget(new QPushButton(tr(&amp;quot;Longer&amp;quot;)));&lt;br /&gt;
    flowLayout-&amp;gt;addWidget(new QPushButton(tr(&amp;quot;Different text&amp;quot;)));&lt;br /&gt;
    flowLayout-&amp;gt;addWidget(new QPushButton(tr(&amp;quot;More text&amp;quot;)));&lt;br /&gt;
    flowLayout-&amp;gt;addWidget(new QPushButton(tr(&amp;quot;Even longer button text&amp;quot;)));&lt;br /&gt;
    setLayout(flowLayout);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Flow Layout&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    Window window;&lt;br /&gt;
    window.show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>