コード例 #1
0
 def create_editor(self, parent, index):
     if index == 1:  # Empty
         editor = QWidget()
     elif index == 2:  # Number filter (>|=|<)
         editor = Widget(parent)
         editor.linee.returnPressed.connect(self.filterActivated)
         editor.btn.clicked.connect(self.changebuttonsymbol)
     elif index == 3:
         editor = QComboBox(parent)
         editor.addItems(["", "Combo", "One", "Two", "Three"])
         editor.currentIndexChanged.connect(self.filterActivated)
     elif index == 4:
         editor = QPushButton(parent)
         editor.clicked.connect(self.filterActivated)
         editor.setText("Button")
         # editor = QPushButton(parent)
         # editor.clicked.connect(self.filterActivated)
         # editor.setText("Button1")
         # editor1 = QPushButton(parent)
         # editor1.clicked.connect(self.filterActivated)
         # editor1.setText("Button")
     elif index == 5:
         editor = QCheckBox(parent)
         editor.clicked.connect(self.filterActivated)
         editor.setTristate(True)
         editor.setCheckState(Qt.Checked)
         editor.setText("CheckBox")
     else:
         editor = QLineEdit(parent)
         editor.setPlaceholderText("Filter")
         editor.returnPressed.connect(self.filterActivated)
     return editor
コード例 #2
0
def set_widget_state(widget: QWidget, config: dict, widget_name=None):
    try:
        if widget_name is None:
            widget_name = widget.objectName()
        if widget_name not in config:
            return
        if isinstance(widget, QLineEdit):
            widget.setText(config[widget_name])
        elif isinstance(widget, QComboBox):
            widget.setUpdatesEnabled(False)
            bs = widget.blockSignals(True)
            widget.clear()
            widget.addItems(config[widget_name]['items'])
            widget.blockSignals(bs)
            widget.setUpdatesEnabled(True)
            widget.setCurrentIndex(config[widget_name]['index'])
            # Force index change event in the case of index=0
            if config[widget_name]['index'] == 0:
                widget.currentIndexChanged.emit(0)
        elif isinstance(widget, QtWidgets.QAbstractButton):
            widget.setChecked(config[widget_name])
        elif isinstance(widget, QPlainTextEdit) or isinstance(
                widget, QtWidgets.QTextEdit):
            widget.setPlainText(config[widget_name])
        elif isinstance(widget, QtWidgets.QSpinBox) or isinstance(
                widget, QtWidgets.QDoubleSpinBox):
            widget.setValue(config[widget_name])
    except:
        return