Qt学习记录4——mainwindow的布局使用

来源:互联网 发布:先导爱知见新导刻小说 编辑:程序博客网 时间:2024/05/19 13:16

最近,一次编程中,我发现在mainwindow中布局是不能正常显示的,这让我伤透了脑筋,为什么不可以呢?又该怎么在mainwindow中对控件进行布局呢?

百度是最好的 老师。我在百度上找到了最后的解决方法,就是在mainwindow中定义一个widget 之后,除了菜单栏,状态栏,工具栏之外,所有的控件都放在widget中。

下面见代码:

QWidget *centerWindow = new QWidget;
        this->setCentralWidget(centerWindow);
        button = new QPushButton("One");
        button2 = new QPushButton("Two");
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(button);
        layout->addWidget(button2);
centerWindow->setLayout(layout);


调试成功~~~

over~~~

0 0