Exemplo n.º 1
0
    def __init__(self, cti, delegate, parent=None):
        """ See the AbstractCtiEditor for more info on the parameters
        """
        super(IntCtiEditor, self).__init__(cti, delegate, parent=parent)

        spinBox = QtWidgets.QSpinBox(parent)
        spinBox.setKeyboardTracking(False)
        setWidgetSizePolicy(spinBox, QtWidgets.QSizePolicy.Expanding, None)

        if cti.minValue is None:
            spinBox.setMinimum(np.iinfo('i').min)
        else:
            spinBox.setMinimum(cti.minValue)

        if cti.maxValue is None:
            spinBox.setMaximum(np.iinfo('i').max)
        else:
            spinBox.setMaximum(cti.maxValue)

        spinBox.setSingleStep(cti.stepSize)
        spinBox.setPrefix(cti.prefix)
        spinBox.setSuffix(cti.suffix)

        if cti.specialValueText is not None:
            spinBox.setSpecialValueText(cti.specialValueText)

        self.spinBox = self.addSubEditor(spinBox, isFocusProxy=True)
        self.spinBox.valueChanged.connect(self.commitChangedValue)
Exemplo n.º 2
0
    def __init__(self,
                 spinBox,
                 slider=None,
                 layoutSpacing=None,
                 layoutContentsMargins=(0, 0, 0, 0),
                 parent=None):
        """ Constructor.

            The settings (min, max, enabled, etc) from the SpinBox will be used for the slider
            as well. That is, the spin box is the master.
        """
        super(SpinSlider, self).__init__(parent=parent)

        check_class(spinBox, QtWidgets.QSpinBox, allow_none=True)
        check_class(slider, QtWidgets.QSlider, allow_none=True)

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(*layoutContentsMargins)
        if layoutSpacing is not None:
            self.layout.setSpacing(layoutSpacing)

        if spinBox is None:
            self.spinbox = QtWidgets.QSpinBox()
        else:
            self.spinbox = spinBox

        if slider is None:
            self.slider = QtWidgets.QSlider(Qt.Horizontal)
        else:
            self.slider = slider

        self.slider.setMinimum(self.spinbox.minimum())
        self.slider.setMaximum(self.spinbox.maximum())
        self.slider.setValue(self.spinbox.value())
        self.slider.setEnabled(self.spinbox.isEnabled())

        self.layout.addWidget(self.spinbox, stretch=0)
        self.layout.addWidget(self.slider, stretch=1)

        self.spinbox.valueChanged.connect(self.slider.setValue)
        self.slider.valueChanged.connect(self.spinbox.setValue)
Exemplo n.º 3
0
    def main():
        import sys

        app = QtWidgets.QApplication(sys.argv)
        window = QtWidgets.QWidget()
        layout = QtWidgets.QVBoxLayout(window)

        if 0:
            if 1:
                window.setStyleSheet("""
                    QLabel {
                        background-color: #FF9900;
                    }
                """)
            else:
                window.setStyleSheet("""
                    QLabel {
                        margin: 5px;
                        border: 0px solid blue;
                        background-color: #FF9900;
                        padding: 0px;
                    }
                """)

        label0 = QtWidgets.QLabel('my great line edit')
        label1 = QtWidgets.QLabel('edit')
        label2 = QtWidgets.QLabel('combo')

        all_labels = [label0, label1, label2]
        for lbl in all_labels:
            _setLabelProps(lbl)
        harmonizeLabelsTextWidth(all_labels)

        maxWidth = labelsMaxTextWidth([label0, label1, label2])
        print("\mmaxWidth: {}".format(maxWidth))

        tableView = QtWidgets.QTableView()
        layout.addWidget(tableView)
        model = QtGui.QStandardItemModel(3, 2)
        tableView.setModel(model)
        tableView.horizontalHeader().resizeSection(0, 200)
        tableView.horizontalHeader().resizeSection(1, 300)
        layoutSpacing = 0

        editor0 = QtWidgets.QSpinBox()
        editor0.setValue(5)
        editor0.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                              QtWidgets.QSizePolicy.MinimumExpanding)
        lw0 = LabeledWidget(label0, editor0, layoutSpacing=layoutSpacing)
        model.setData(model.index(0, 0), "A small")
        tableView.setIndexWidget(model.index(0, 1), lw0)

        editor1 = QtWidgets.QSpinBox()
        editor1.setValue(7)
        editor1.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                              QtWidgets.QSizePolicy.MinimumExpanding)
        lw1 = LabeledWidget(label1, editor1, layoutSpacing=layoutSpacing)
        model.setData(model.index(1, 0), "A SMALL seasoned curly")
        tableView.setIndexWidget(model.index(1, 1), lw1)

        comboBox = QtWidgets.QComboBox()
        comboBox.addItems([
            "Half diet coke", "Half regular coke",
            "Junior western bacon cheese"
        ])
        lw2 = LabeledWidget(label2, comboBox, layoutSpacing=layoutSpacing)
        model.setData(model.index(2, 0), "What else?")
        tableView.setIndexWidget(model.index(2, 1), lw2)

        window.resize(550, 400)
        window.show()
        window.raise_()
        sys.exit(app.exec_())