Ejemplo n.º 1
0
    def widget(self):
        """Get the QWidget of the Field."""
        widget = QtWidgets.QWidget()
        hbox = QtWidgets.QHBoxLayout(widget)
        hbox.setContentsMargins(0, 0, 0, 0)
        label = QtWidgets.QLabel('Relative to')
        label.setSizePolicy(QtWidgets.QSizePolicy.Maximum,
                            QtWidgets.QSizePolicy.Fixed)
        hbox.addWidget(label)
        relative_combobox = QtWidgets.QComboBox()
        relative_combobox.addItems(FilePathField.relative_to_choices)
        index = relative_combobox.findText(self.relative_to)
        if index != -1:
            relative_combobox.setCurrentIndex(index)
        relative_combobox.currentIndexChanged.connect(self.set_relative_to)
        hbox.addWidget(relative_combobox)

        line_edit = QtWidgets.QLineEdit(self._value)
        line_edit.setToolTip(self.help_text)
        line_edit.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                QtWidgets.QSizePolicy.Fixed)
        line_edit.textChanged.connect(self.set_value)
        hbox.addWidget(line_edit)
        button = QtWidgets.QPushButton('Browse')
        button.released.connect(
            partial(self.browse, line_edit, relative_combobox))
        hbox.addWidget(button)
        return widget
Ejemplo n.º 2
0
    def widget(self):
        """Get the QWidget of the Field."""
        if self.choices:
            widget = QtWidgets.QComboBox()
            widget.setEditable(self.editable)
            for choice in self.choices:
                widget.addItem(choice, choice)
            index = widget.findText(self._value)
            if index == -1:
                widget.addItem(self._value, self._value)
                widget.setCurrentIndex(widget.count() - 1)
            else:
                widget.setCurrentIndex(index)

            widget.currentIndexChanged.connect(self.set_value)
        else:
            widget = QtWidgets.QLineEdit(self._value)
            widget.textChanged.connect(self.set_value)
        widget.setToolTip(self.help_text)
        return widget