QT4:水平布局管理器QHBoxLayout

来源:互联网 发布:淘宝店铺网红 编辑:程序博客网 时间:2024/05/29 12:09

 

创建一个窗体并排摆放一个按钮一个标签,使他们能够随着窗体的水平缩放而缩放。
实现这个功能需要使用布局管理器中的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();
}
 

0 0
原创粉丝点击