pyqtgraph:对于<GLViewWidget实例中的项目>.items仅每隔一个项目显示一次



我可以重现pyqtgraph示例GLLinPlotItem.py中的问题。我刚刚添加了行

print (w.items)     
for item in w.items:
if (type (item) == gl.GLLinePlotItem): 
print (item)
w.removeItem (item)

在用GLLinePlotItems加载绘图的for循环之后。

while print(w.items(打印我的for循环打印的所有项目,并且仅每隔一秒删除一个。

我发现了这个线程:Python只针对每秒一次的循环Item,但没有解决方案。

有什么想法吗?

非常感谢

Martin

编辑:如果你评论w.removeItem,它会打印所有项目。

好吧,我发现自己:removeItem更改列表,将每个后续项向前移动一个索引,而循环索引保持不变。所以for内部循环只是通过索引进行循环。我以为他们会考虑到名单的变化。又学到了新东西:-(所以我的解决方案是从后面查看列表,所以删除一个项目不会影响索引,因为它从前面计数:

itm_cnt = len (w.items)
idx = itm_cnt - 1
print (itm_cnt)    
while (idx >= 0):
if (type (w.items [idx]) == gl.GLLinePlotItem): 
print (idx, w.items [idx])
#        w.removeItem (w.items [idx])
del w.items [idx]
idx -= 1

我希望这能帮助其他人。Martin

最新更新