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