def __init__(self): QtGui.QWidget.__init__(self) self.slider = QFloatSlider(QtCore.Qt.Horizontal) self.spinbox = QtGui.QDoubleSpinBox() # Fill background to avoid to see text or widget behind self.setAutoFillBackground(True) AbstractFloatWidget.__init__(self) # To be compatible with tree or table views, slider must keep focus self.slider.setFocusPolicy(QtCore.Qt.StrongFocus) self.setMinimumHeight(22) self.spinbox.setMinimumHeight(18) self.slider.setMinimumHeight(18) self.slider.floatValueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.slider.setFloatValue) # self.slider.floatValueChanged.connect(self.valueChanged) self.spinbox.valueChanged.connect(self.valueChanged) layout = QtGui.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.spinbox) layout.addWidget(self.slider) self.value_changed_signal = self.valueChanged
class FloatSlider(QtGui.QWidget, AbstractFloatWidget): valueChanged = QtCore.Signal(float) def __init__(self): QtGui.QWidget.__init__(self) self.slider = QFloatSlider(QtCore.Qt.Horizontal) self.spinbox = QtGui.QDoubleSpinBox() # Fill background to avoid to see text or widget behind self.setAutoFillBackground(True) AbstractFloatWidget.__init__(self) # To be compatible with tree or table views, slider must keep focus self.slider.setFocusPolicy(QtCore.Qt.StrongFocus) self.setMinimumHeight(22) self.spinbox.setMinimumHeight(18) self.slider.setMinimumHeight(18) self.slider.floatValueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.slider.setFloatValue) # self.slider.floatValueChanged.connect(self.valueChanged) self.spinbox.valueChanged.connect(self.valueChanged) layout = QtGui.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.spinbox) layout.addWidget(self.slider) self.value_changed_signal = self.valueChanged def reset(self, value=1.0, minimum=0.0, maximum=1.0, step=0.01, **kwargs): if minimum is not None: self.slider.setMinimum(minimum / step) self.spinbox.setMinimum(minimum) if maximum is not None: self.slider.setMaximum(maximum / step) self.spinbox.setMaximum(maximum) self.spinbox.setSingleStep(step) if step < 0.01: self.spinbox.setDecimals(3) else: self.spinbox.setDecimals(2) self.slider.setStep(step) self.setValue(value) def apply(self, control): AbstractQtControlWidget.apply(self, control) control.interface.min = self.spinbox.minimum() control.interface.max = self.spinbox.maximum() control.interface.step = self.spinbox.singleStep() def value(self, interface=None): return self.spinbox.value() def step(self): # return self.slider.slider_step return self.spinbox.singleStep() def setValue(self, value): self.slider.setFloatValue(value) self.spinbox.setValue(value)
def __init__(self): QFloatSlider.__init__(self) AbstractFloatWidget.__init__(self) self.value_changed_signal = self.floatValueChanged self.setMinimumWidth(18)