Example #1
0
    def __init__(self, label, value, min, max, axis, parent=None, step=0.1, setDecimals=2):
        """Creates a double spinbox for axis and lays them out in a horizontal layout
        We give access to each spinbox with a property eg. self.x which returns the float value

        :param label: the label for the vector eg. translate, if the label is None or "" then it will be excluded
        :type label: str
        :param value: n floats corresponding with axis param
        :type value: tuple(float)
        :param min: the min value for all three elements of the vector
        :type min: float
        :param max: the max value for all three elements of the vector
        :type max: float
        :param axis: every axis which will have a doubleSpinBox eg. [X,Y,Z] or [X,Y,Z,W]
        :type axis: list
        :param parent: the widget parent
        :type parent: QtWidget
        :param step: the step amount while clicking on the spin box or keyboard up/down
        :type step: float
        """
        super(VectorSpinBox, self).__init__(parent=parent)
        self.mainLayout = HBoxLayout(parent, (2, 2, 2, 2), uiconstants.SREG)
        if label:
            self.label = QtWidgets.QLabel(label, parent=self)
            self.mainLayout.addWidget(self.label)
        self._widgets = OrderedDict()
        # todo: STYLESHEET needs to be in stylesheet and prefs
        # rgb(27, 27, 27) is the QLineEdit/QDoubleSpinBox color
        # images will need to be added and tweaked for hover states and press
        borderSize = utils.dpiScale(3)
        styleSheet = "QDoubleSpinBox {0} border: {2}px solid rgb(27, 27, 27); " \
                     "border-radius: 0px; {1}".format("{", "}", borderSize)

        for i, v in enumerate(axis):
            box = QtWidgets.QDoubleSpinBox(self)
            box.setSingleStep(step)
            box.setObjectName("".join([label, v]))
            box.setRange(min, max)
            box.setValue(value[i])
            box.setDecimals(setDecimals)
            box.valueChanged.connect(self.onValueChanged)
            box.setStyleSheet(styleSheet)
            self._widgets[v] = box
            self.mainLayout.addWidget(box)

        self.setLayout(self.mainLayout)
Example #2
0
 def createEditor(self, parent, option, index):
     model = index.model()
     widget = QtWidgets.QDoubleSpinBox(parent=parent)
     widget.setMinimum(model.data(index, constants.minValue))
     widget.setMaximum(constants.maxValue)
     return widget