Repository: pyqtgraph/pyqtgraph

Issue:
Bug in slider parameter
<!-- In the following, please describe your issue in detail! -->
<!-- If some sections do not apply, just remove them. -->

### Short description
<!-- This should summarize the issue. -->
Bug that precludes use of suffix in SliderParameter
### Code to reproduce
<!-- Please provide a minimal working example that reproduces the issue in the code block below.
     Ideally, this should be a full example someone else could run without additional setup. -->

```python
import pyqtgraph as pg
import numpy as np
from pyqtgraph.parametertree import (Parameter, ParameterTree, registerParameterType)

        ...
        colorParams = [
            dict(name='Color Settings', type='group', children=[
                dict(name='Opacity', type='slider', limits=[0,100], value = 60.0, suffix='%'),
            ]),
        ]
        self.parameters = pg.parametertree.Parameter.create(name='Analysis Settings', type='group', children=colorParams)
        ...
```

### Expected behavior
<!-- What should happen? -->
Slider should show a number 0 - 100, followed by a '%' suffix

### Real behavior
<!-- What happens? -->
Application crashes, as it refers to a non-existing method
```
An error occurred?
Post the full traceback inside these 'code fences'!

AttributeError
'SliderParameterItem' object has no attribute '_updateLabel'
```

### Solution
 1. Please delete line 32, containing ``` self._updateLabel(self.slider.value())``` as this method does not exist
 2. After ```layout = QHBoxLayout()``` Please add a line containing ```layout.setContentsMargins(0, 0, 0, 0)```
 3. In doing so, the height of the slider item stays equal to the other items (=20), now there is a *bulge*

### Additional context
None
Bug in slider parameter
<!-- In the following, please describe your issue in detail! -->
<!-- If some sections do not apply, just remove them. -->

### Short description
<!-- This should summarize the issue. -->
Bug that precludes use of suffix in SliderParameter
### Code to reproduce
<!-- Please provide a minimal working example that reproduces the issue in the code block below.
     Ideally, this should be a full example someone else could run without additional setup. -->

```python
import pyqtgraph as pg
import numpy as np
from pyqtgraph.parametertree import (Parameter, ParameterTree, registerParameterType)

        ...
        colorParams = [
            dict(name='Color Settings', type='group', children=[
                dict(name='Opacity', type='slider', limits=[0,100], value = 60.0, suffix='%'),
            ]),
        ]
        self.parameters = pg.parametertree.Parameter.create(name='Analysis Settings', type='group', children=colorParams)
        ...
```

### Expected behavior
<!-- What should happen? -->
Slider should show a number 0 - 100, followed by a '%' suffix

### Real behavior
<!-- What happens? -->
Application crashes, as it refers to a non-existing method
```
An error occurred?
Post the full traceback inside these 'code fences'!

AttributeError
'SliderParameterItem' object has no attribute '_updateLabel'
```

### Solution
 1. Please delete line 32, containing ``` self._updateLabel(self.slider.value())``` as this method does not exist
 2. After ```layout = QHBoxLayout()``` Please add a line containing ```layout.setContentsMargins(0, 0, 0, 0)```
 3. In doing so, the height of the slider item stays equal to the other items (=20), now there is a *bulge*

### Additional context
None


Discussion:

Resolving patch:
diff --git a/pyqtgraph/parametertree/parameterTypes/slider.py b/pyqtgraph/parametertree/parameterTypes/slider.py
--- a/pyqtgraph/parametertree/parameterTypes/slider.py
+++ b/pyqtgraph/parametertree/parameterTypes/slider.py
@@ -20,6 +20,7 @@ def __init__(self, param, depth):
     def updateDisplayLabel(self, value=None):
         if value is None:
             value = self.param.value()
+        self.sliderLabel.setText(self.prettyTextValue(self.slider.value()))
         value = str(value)
         if self._suffix is None:
             suffixTxt = ''
@@ -27,9 +28,13 @@ def updateDisplayLabel(self, value=None):
             suffixTxt = f' {self._suffix}'
         self.displayLabel.setText(value + suffixTxt)
 
+
     def setSuffix(self, suffix):
         self._suffix = suffix
-        self._updateLabel(self.slider.value())
+        # This may be called during widget construction in which case there is no
+        # displayLabel yet
+        if hasattr(self, 'displayLabel'):
+            self.updateDisplayLabel(self.slider.value())
 
     def makeWidget(self):
         param = self.param
@@ -39,7 +44,7 @@ def makeWidget(self):
 
         self.slider = QtWidgets.QSlider()
         self.slider.setOrientation(QtCore.Qt.Orientation.Horizontal)
-        lbl = QtWidgets.QLabel()
+        lbl = self.sliderLabel = QtWidgets.QLabel()
         lbl.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
 
         w = QtWidgets.QWidget()
@@ -54,10 +59,7 @@ def setValue(v):
         def getValue():
             return self.span[self.slider.value()].item()
 
-        def vChanged(v):
-            lbl.setText(self.prettyTextValue(v))
-
-        self.slider.valueChanged.connect(vChanged)
+        self.slider.valueChanged.connect(self.updateDisplayLabel)
 
         def onMove(pos):
             self.sigChanging.emit(self, self.span[pos].item())
@@ -109,7 +111,6 @@ def optsChanged(self, param, opts):
         w.setMaximum(len(span) - 1)
         if 'suffix' in opts:
             self.setSuffix(opts['suffix'])
-            self.slider.valueChanged.emit(self.slider.value())
 
     def limitsChanged(self, param, limits):
         self.optsChanged(param, dict(limits=limits))


Test patch: