我有一个自定义小部件,它在行中显示许多项目:
void update(){ //this is a SLOT which is connected to a button click
QVBoxLayout *layout = this->layout();
if (layout == NULL){
layout = new QVBoxLayout;
this->setLayout(layout);
} else {
QLayout_clear(layout); //this is a function that I wrote that deletes all of the items from a layout
}
ArrayList *results = generateData(); //this generates the data that I load from
for (int i = 0; i < results->count; i++){
layout->addWidget(new subWidget(results->array[i]));
}
}
问题是大约有 900 个项目,并且配置文件显示简单地将子对象添加到布局中需要 50% 的时间(构建需要另外 50% 的时间)。总体而言,加载所有项目大约需要 3 秒。
当我单击按钮加载更多数据时,整个 UI 会冻结 3 秒钟,然后在一切完成后所有项目一起出现。有没有办法在创建更多项目时逐步加载它们?