Exemple #1
0
class CheckWidget(QWidget):

    valueModified = pyqtSignal()
    valueChosen = pyqtSignal(object)

    def __init__(self, parent, inner, curvalue, client):
        QWidget.__init__(self, parent)
        layout = self._layout = QHBoxLayout()
        self.checkbox = QCheckBox(self)
        if curvalue is not None:
            self.checkbox.setCheckState(Qt.Checked)
        if curvalue is None:
            curvalue = inner()  # generate a dummy value
        self.inner_widget = create(self, inner, curvalue, client=client)
        self.inner_widget.setEnabled(self.checkbox.isChecked())
        self.inner_widget.valueModified.connect(self.valueModified)
        layout.addWidget(self.checkbox)
        layout.addWidget(self.inner_widget)
        layout.setContentsMargins(0, 0, 0, 0)
        self.checkbox.stateChanged.connect(self.on_checkbox_stateChanged)
        self.setLayout(layout)

    def on_checkbox_stateChanged(self, state):
        self.inner_widget.setEnabled(state == Qt.Checked)
        self.valueModified.emit()

    def getValue(self):
        if self.checkbox.isChecked():
            return self.inner_widget.getValue()
        return None
Exemple #2
0
 def __init__(self, parent, values, curvalue, client):
     QWidget.__init__(self, parent)
     layout = self._layout = QVBoxLayout()
     self.checkboxes = []
     self.values = []
     curvalue = curvalue or set()
     for value in values:
         checkbox = QCheckBox(str(value), self)
         if value in curvalue:
             checkbox.setCheckState(Qt.Checked)
         checkbox.stateChanged.connect(self.on_checkbox_stateChanged)
         layout.addWidget(checkbox)
         self.checkboxes.append(checkbox)
     layout.setContentsMargins(0, 0, 0, 0)
     self.setLayout(layout)