简体   繁体   English

QTreeWidget两次添加相同的项目

[英]QTreeWidget add same item twice

I'm trying to make some kind of recursion. 我正在尝试进行某种递归。 If you open P then you can open P again or do something else. 如果您打开P则可以再次打开P或执行其他操作。 And here is my problem: 这是我的问题:
I can't add same item twice. 我不能两次添加相同的项目。

while (*it) {
    if ((*it)->text(0) == item->text(0)){
        (*it)->setText(0,"Add_item");
        (*it)->addChild(item);
    }
}

Can I make a loop in QTree ? 我可以在QTree循环吗?

You need to create another item. 您需要创建另一个项目。 It seems you add for the same text the same item object over and over again as child. 似乎您一次又一次地为相同的文本添加相同的项目对象。 So making a copy of the item and adding that copy as child should work. 因此,制作该项目的副本并将该副本作为子项添加应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM