QHBoxLayout 类

QHBoxLayout 类水平排列 Widget。 更多...

头: #include <QHBoxLayout>
qmake: QT += widgets
继承: QBoxLayout

公共函数

QHBoxLayout ()
QHBoxLayout (QWidget * parent )
~QHBoxLayout ()

额外继承成员

详细描述

QHBoxLayout 类水平排列 Widget。

此类用于构造水平框布局对象。见 QBoxLayout 了解细节。

类的最简单用法像这样:

    QWidget *window = new QWidget;
    QPushButton *button1 = new QPushButton("One");
    QPushButton *button2 = new QPushButton("Two");
    QPushButton *button3 = new QPushButton("Three");
    QPushButton *button4 = new QPushButton("Four");
    QPushButton *button5 = new QPushButton("Five");
    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    layout->addWidget(button4);
    layout->addWidget(button5);
    window->setLayout(layout);
    window->show();
					

首先,我们创建希望在布局中的 Widget。然后,创建 QHBoxLayout 对象并把 Widget 添加到布局。最后,调用 QWidget::setLayout () 安装 QHBoxLayout 对象到 Widget。此时,布局中的 Widget 被重设父级以让 window 作为其父级。

Horizontal box layout with five child widgets

另请参阅 QVBoxLayout , QGridLayout , QStackedLayout , 布局管理 ,和 基本布局范例 .

成员函数文档编制

QHBoxLayout:: QHBoxLayout ()

构造新的水平框。必须把它添加到另一布局。

QHBoxLayout:: QHBoxLayout ( QWidget * parent )

构造新的顶层水平框采用父级 parent .

QHBoxLayout:: ~QHBoxLayout ()

销毁此框布局。

布局的 Widget 不被销毁。