• 6385阅读
  • 4回复

[提问]QWidget控件如何自动填充满QDockWidget [复制链接]

上一主题 下一主题
离线lgs_shandong
 

只看楼主 倒序阅读 楼主  发表于: 2016-01-23
在vs2008中,添加了一个基于QWidget派生的类QCommandLine,在ui中设计完成了界面,然后使用代码把它添加到QDockWidget中,结果发现无法自动填充,结果如下

离线wanghouting

只看该作者 1楼 发表于: 2016-01-24
给个layout?
去年我借给你的5块钱啥时候还?
离线lgs_shandong

只看该作者 2楼 发表于: 2016-01-24
cmdLine = new QCommandLine();    
commandLineDock = new QDockWidget(tr("Command Line"), this);    
QHBoxLayout *hbLayout = new QHBoxLayout(commandLineDock);    
hbLayout->addWidget(cmdLine);    
commandLineDock->setWidget(cmdLine);

这样还是不可以,cmdLine是一个QWidget派生的类,在designer中设计好界面之后,然后在主窗体的构造函数中进行设置。

commandLineDock 是在主窗体中定义的变量。
离线lgs_shandong

只看该作者 3楼 发表于: 2016-01-24
为什么使用QUiLoader加载ui文件,然后commandLineDock->setWidget(formWidget);这样可以自动填充满dock区域,使用前面的方法就不行?

有人吗?
离线yl19823442

只看该作者 4楼 发表于: 2016-01-25
回 lgs_shandong 的帖子
lgs_shandong:cmdLine = new QCommandLine();    
commandLineDock = new QDockWidget(tr("Command Line"), this);    
QHBoxLayout *hbLayout = new QHBoxLayout(commandLineDock);    
hbLayout->addWidget(cmdLin .. (2016-01-24 09:57) 

commandLineDock->setWidget(cmdLine);
是不是应该改成:commandLineDock->setLayout(hbLayou); 呢?
要不然布局还是没有被应用,你试一下。
快速回复
限100 字节
 
上一个 下一个