您的位置:首页 > 编程语言 > Qt开发

QT4:水平布局管理器QHBoxLayout

2016-09-01 21:58 465 查看
 



创建一个窗体并排摆放一个按钮一个标签,使他们能够随着窗体的水平缩放而缩放。

实现这个功能需要使用布局管理器中的QHBoxLay进行布局,把这连个组件放入QHBoxlayout中。

#include <QApplication>

#include <QLabel>

#include <QPushButton>

#include <QHBoxLayout>

#include <QWidget>

int main(int argc, char *argv[])

{

    QApplication app (argc, argv);

 QHBoxLayout *hlayout=new QHBoxLayout();

 QPushButton *button=new QPushButton("im ok");

    QLabel *label = new QLabel("Hello Qt!");

    QWidget *window = new QWidget;

    window->setWindowTitle("main");

    hlayout->addWidget(button);

    hlayout->addWidget(label);

    window->setLayout(hlayout);

    window->show();

    return app.exec();

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: