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);