Repository: pyqtgraph/pyqtgraph

Issue:
GITHUB pyqtgraph error : 'NoneType' object has no attribute 'setFirstItemColumnSpanned'
Considering your last comment on using the latest from GITHUB, I tried using the latest package and see the following traceback. My parameter tree may have an error? However the same paramtertree setup works with pyqtgraph 0.10.0.

Python 3.5.4, PyQt 5.11.2, pyqtgraph (2018-07-22)

```
  File "lib\_test\test.py", line 629, in <module>
    p.setup_map_control(d)
  File "lib\_test\test.py", line 490, in setup_map_control
    t.setParameters(self.ptree1, showTop=False)
  File "lib\pyqtgraph\parametertree\ParameterTree.py", line 46, in setParameters
    self.clear()
  File "lib\pyqtgraph\parametertree\ParameterTree.py", line 83, in clear
    self.invisibleRootItem().takeChildren()
  File "lib\pyqtgraph\widgets\TreeWidget.py", line 392, in takeChildren
    TreeWidget.informTreeWidgetChange(child)
  File "lib\pyqtgraph\widgets\TreeWidget.py", line 172, in informTreeWidgetChange
    item.treeWidgetChanged()
  File "lib\pyqtgraph\parametertree\parameterTypes.py", line 429, in treeWidgetChanged
    self.treeWidget().setFirstItemColumnSpanned(self, True)
AttributeError: 'NoneType' object has no attribute 'setFirstItemColumnSpanned'
```


Discussion:
@apiszcz sorry we're following up so late with you.  Can you post the steps you used to generate this error?
Don't have enough here to reproduce, @apiszcz if you are still having this issue and can give us some code to run that replicates the fault, let us know and we'll re-open the issue.  Thanks
@j9ac9k I have the same Problem with the self.clear() function of the class ParameterTree.
My issue is to collapse the tree-elements.
I want to change the options of the Parameter (expanded) and then set those Parameters to the Parameter Tree. But when there are some Parameters in it yet, the self.clear()-Function throws this error.

Is there another way to collapse/expand the items?

Thanks for help!

Here is my Code for the error:
```
from PyQt5.QtWidgets import QApplication
from pyqtgraph.parametertree import Parameter, ParameterTree
import sys

app = QApplication.instance()
if app is None:
    app = QApplication(sys.argv)

#Create a Tree of Parameters
allparameter = Parameter.create(name = "allParameter", type = 'group')
b1 = Parameter.create(name = "block1", type = 'group')
b2 = Parameter.create(name = "block2", type = 'group')
c1 = Parameter.create(name = "child1", type = 'str')
c2 = Parameter.create(name = "child2", type = 'bool', value = True)
c3 = Parameter.create(name = "child3", type = 'int', value = 10)
c4 = Parameter.create(name = "child4", type = 'float')
c3.addChild(c4)
b1.addChildren([c1, c2, c3])
b2.addChild(c3)
allparameter.addChildren([b1,b2])

#Create Parametertree-Object
tree = ParameterTree()
tree.setParameters(allparameter, showTop=False)
tree.clear()
```
For what it's worth, I did not have this issue in pyqtgraph 0.10.0, but it appeared for me on the 'develop' branch install.
Bisect uncovered this as the first bad commit: https://github.com/pyqtgraph/pyqtgraph/pull/518/commits/3fbc3864f2611d385bd88d4f2becf94a9a6f3722. I need to work on understanding the ParameterTree system a little better, but there's a start.

Resolving patch:
diff --git a/pyqtgraph/parametertree/parameterTypes.py b/pyqtgraph/parametertree/parameterTypes.py
--- a/pyqtgraph/parametertree/parameterTypes.py
+++ b/pyqtgraph/parametertree/parameterTypes.py
@@ -426,10 +426,13 @@ def addChanged(self):
 
     def treeWidgetChanged(self):
         ParameterItem.treeWidgetChanged(self)
-        self.treeWidget().setFirstItemColumnSpanned(self, True)
+        tw = self.treeWidget()
+        if tw is None:
+            return
+        tw.setFirstItemColumnSpanned(self, True)
         if self.addItem is not None:
-            self.treeWidget().setItemWidget(self.addItem, 0, self.addWidgetBox)
-            self.treeWidget().setFirstItemColumnSpanned(self.addItem, True)
+            tw.setItemWidget(self.addItem, 0, self.addWidgetBox)
+            tw.setFirstItemColumnSpanned(self.addItem, True)
         
     def addChild(self, child):  ## make sure added childs are actually inserted before add btn
         if self.addItem is not None:
@@ -664,8 +667,12 @@ def treeWidgetChanged(self):
         ## TODO: fix so that superclass method can be called
         ## (WidgetParameter should just natively support this style)
         #WidgetParameterItem.treeWidgetChanged(self)
-        self.treeWidget().setFirstItemColumnSpanned(self.subItem, True)
-        self.treeWidget().setItemWidget(self.subItem, 0, self.textBox)
+        tw = self.treeWidget()
+        if tw is None:
+            return
+
+        tw.setFirstItemColumnSpanned(self.subItem, True)
+        tw.setItemWidget(self.subItem, 0, self.textBox)
         
         # for now, these are copied from ParameterItem.treeWidgetChanged
         self.setHidden(not self.param.opts.get('visible', True))


Test patch: