• 2807阅读
  • 1回复

[讨论]QT如何在ui中已经放置的QGroupBox中使用代码布局 [复制链接]

上一主题 下一主题
离线dxa572862121
 

只看楼主 倒序阅读 楼主  发表于: 2018-02-01
实现代码和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楼 发表于: 2018-02-01
这样不能在设计器显示的。运行就会显示了
本是后山人,偶作前堂客,醉舞经阁半卷书,坐井说天阔。大志戏功名,海斗量福祸,论到囊中羞涩时,怒指乾坤错
QQ:874164244
快速回复
限100 字节
 
上一个 下一个