QT5 QGridLayout使用中遇到问题,layout中所有控件挤到一起去了

alpmt alpmt 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题,直接先贴代码,工程是直接VS2013自动生成的QT5 GUI Application
在QtGuiApplication1.cpp中代码如下

#include "QtGuiApplication1.h"
#include <qpushbutton.h>
#include <qgridlayout.h>
QtGuiApplication1::QtGuiApplication1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);

QPushButton *p1, *p2;
p1 = new QPushButton(this);
p2 = new QPushButton(this);
p1->setText("1");
p2->setText("2");
QGridLayout *lay;
lay = new QGridLayout(this);
lay->addWidget(p1, 0, 0, 1, 1);
lay->addWidget(p2, 0, 1, 1, 1);

this->setLayout(lay);

}


结果出来的是
但是如果上面代码放在main.cpp里面就没有任何问题,可以得到理想的结果,这是为什么呢
...全文
评论 4
收藏 已收藏
分享
返回顶部
alpmt
工具平台和程序库 24,850 成员 27,330 内容