def __init__(self, valueController, parent=None): super(StringEditor, self).__init__(valueController, parent=parent) vbox = QtWidgets.QVBoxLayout() self._editor = QtWidgets.QTextEdit(self) options = valueController.getOption('multiLine') self._editor.setMinimumHeight(options.get('numLines', 5) * 20) self._editor.setMaximumHeight(options.get('numLines', 5) * 20) vbox.addWidget(self._editor, 1) # vbox.addStretch(0) vbox.setContentsMargins(0, 0, 0, 0) self.setLayout(vbox) self.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) self.updateEditorValue() # we get lots of 'editingFinished' events, # so filter to only generate undos for important ones. self._value = self._editor.toPlainText() def invokeSetter(): value = self._editor.toPlainText() if self._value != value: self._value = value self._setValueToController() self._editor.textChanged.connect(self._setValueToController) self.setEditable(valueController.isEditable())
def createLayout(self): self._mainLayout = QtWidgets.QVBoxLayout() self._mainLayout.setContentsMargins(10, 10, 10, 10) self._commentTextEdit = QtWidgets.QTextEdit(self) self._commentTextEdit.setText(self.nodeItem.getComment()) self._commentTextEdit.setMinimumHeight(20) self._commentTextEdit.setMaximumHeight(40) self._settingsLayout = QtWidgets.QGridLayout() self._settingsLayout.setContentsMargins(10, 10, 10, 10) self._settingsLayout.setSpacing(3) self._settingsLayout.setColumnMinimumWidth(0, 75) self._settingsLayout.setColumnStretch(0, 0) self._settingsLayout.setColumnStretch(1, 1) # Settings widgets self._colorLabel = QtWidgets.QLabel('Color', self) self._colorLabel.setObjectName('color_label') self._colorLabel.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Fixed) self._colorLabel.setMinimumWidth(75) self._colorWidget = KColorWidget(self, self.nodeItem.getColor()) self._settingsLayout.addWidget(self._colorLabel, 0, 0, 1, 1, alignment=QtCore.Qt.AlignLeft) self._settingsLayout.addWidget(self._colorWidget, 0, 1, 1, 1, alignment=QtCore.Qt.AlignLeft) # OK and Cancel buttons self.buttons = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self) self._mainLayout.addWidget(self._commentTextEdit) self._mainLayout.addLayout(self._settingsLayout) self._mainLayout.addStretch(1) self._mainLayout.addWidget(self.buttons) self.setLayout(self._mainLayout)