标题:QListBox使用注意
作者:浪漫天使
日期:2006-04-29 11:31
内容:
void classname::slot_DelCondition()
{
int i=0;
// QListBoxItem *tmpitem = NULL;
int num = ConditionListBox->count();
// printf("num =%d\n",num);
i = num;
//when we delete a list item , the num will -1 the num has change, so we must deletefrom tail
while (i)
{
i--;
if(ConditionListBox->isSelected(i))
{
// printf("%d is selected \n",i);
ConditionListBox->removeItem(i);
}
}
/********************
// 这里的num没有及时的根新,还是原来的count()的返回值
for(i=0;iitem(i);
/////////////////
if(ConditionListBox->isSelected(i))
{
printf("%d is selected \n",i);
ConditionListBox->removeItem(i);
}
////////////////////////////////
///////////////////////////
QListBoxItem *tmpitem = ConditionListBox->item(i);
printf("the %d address of tmpitem is %x\n",i,tmpitem);
if(tmpitem && (tmpitem->isSelected()) )
{
int x= ConditionListBox->index(tmpitem);
printf("%d is selected address is %x\n",x,tmpitem);
ConditionListBox->removeItem(x);
// 这以后 count()的返回值改变了
// ConditionListBox->takeItem(tmpitem);
// ConditionListBox->update();
}
///////////////////////////
}
**********************/
}
当我们需要删除QListBox里面得QListViewItem的时候,要注意从后面删除。因为当你删除一项的时候,QListBox 的数目会动态的更新,所以,如果是用for循环的 ..