Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
None
-
5.9.3
-
None
-
windows 10
Description
I call the insertItem() function of QListWidget to insert a data in the first line,But always insert in the last line.
My code is as follows:
AreaSelectUnitWidget* pUnit = new AreaSelectUnitWidget(this); // new a widget
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
ui->listWidget->insertItem(0,item); // I want to insert it in the first line every time
ui->listWidget->setItemWidget(item,pUnit); // set widget as item
When i call the above code as a function several times,my new inserted widget item always inserted in the last line,not the first line.
Why doesn't it work?Some people say don't write like that : "new QListWidgetItem(ui->listWidget);", I tried not to use "ui->listWidget" as it parent object,But it still didn't work.Please tell me what should i do?I am a chinese,My english is not good,so please explain it in detail,thanks!