首页| 论坛| 消息

标题:QT如何在ui中已经放置的QGroupBox中使用代码布局
作者:dxa572862121
日期:2018-02-01 16:57
内容:

实现代码和ui结合布局,怎么实现。。
贴上代码
//测试
//Widget中代码
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QLabel *a=new myLabel(ui->groupBox);
    a->setText("hello");
    a->show();
    QLabel *b=new myLabel(ui->groupBox);
    b->setText("hello");
    b->show();
    QLabel *c=new myLabel(this);
    c->setText("hello");
    c->show();
    QLabel *d=new myLabel(this);
    d->setText("hello");
    d->show();
    myLabel *e=new myLabel(this);
    myLabel *f=new myLabel(this);
    QVBoxLayout *l=new QVBoxLayout;
    l->addWidget(a);
    l->addWidget(b);
    l->addWidget(c);
    l->addWidget(d);
    l->addStretch(2);
    
    ui->groupBox->setLayout(l);
    ui->groupBox->show();
}


这样做就是什么都不显示。。。。


#1 [大漠之鹰 02-01 20:48]
这样不能在设计器显示的。运行就会显示了

回复 发表
主题 版块