Qt5:从buttom动态添加QLabel到顶部

问题描述

我正在使用QVboxLayout实现此目的。 下面的代码是我目前正在尝试的代码:

BubbleLabel *label = new BubbleLabel();
label->setText(text);
ui->verticalLayout->insertWidget(-1,label);

结果是从顶部到顶部,而不是从顶部到顶部:

enter image description here

我希望它以这种方式显示:

enter image description here

我该如何实现?

解决方法

插入将“放置位置”作为索引。 您应该使用:

ui->verticalLayout->insertWidget(0,label);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...