class NodeItemWidget(QWidget): nodeUpdated = Signal(object) removePoint = Signal(object) def __init__(self): super(NodeItemWidget, self).__init__() self.node = None self.valueEdit = QLineEdit() self.opacityEdit = QLineEdit() self.colorButton = ColorButton() self.colorButton.setMaximumWidth(100) self.deleteButton = QPushButton("x") layout = QGridLayout() layout.addWidget(QLabel("Value:"), 0, 0) layout.addWidget(QLabel("Opacity:"), 0, 1) layout.addWidget(QLabel("Color:"), 0, 2) layout.addWidget(self.valueEdit, 1, 0) layout.addWidget(self.opacityEdit, 1, 1) layout.addWidget(self.colorButton, 1, 2) layout.addWidget(self.deleteButton, 1, 3) self.colorButton.clicked.connect(self.showColorDialog) self.deleteButton.clicked.connect(self.deleteNode) self.setLayout(layout) def setNode(self, node): self.node = node if not node: self.setEnabled(False) self.valueEdit.setText(" ") self.opacityEdit.setText(" ") self.colorButton.setColor([0.8, 0.8, 0.8]) return self.setEnabled(True) self.valueEdit.setText("%.1f" % self.node.value) self.opacityEdit.setText("%.3f" % self.node.opacity) self.colorButton.setColor(self.node.color) def deleteNode(self): self.removePoint.emit(self.node) def showColorDialog(self): color = QColorDialog.getColor() if not color.isValid(): return rgba = list(color.getRgbF()) self.node.color = [rgba[0], rgba[1], rgba[2]] self.colorButton.setColor(self.node.color) self.nodeUpdated.emit(self.node)
def __init__(self): super(NodeItemWidget, self).__init__() self.node = None self.valueEdit = QLineEdit() self.opacityEdit = QLineEdit() self.colorButton = ColorButton() self.colorButton.setMaximumWidth(100) self.deleteButton = QPushButton("x") layout = QGridLayout() layout.addWidget(QLabel("Value:"), 0, 0) layout.addWidget(QLabel("Opacity:"), 0, 1) layout.addWidget(QLabel("Color:"), 0, 2) layout.addWidget(self.valueEdit, 1, 0) layout.addWidget(self.opacityEdit, 1, 1) layout.addWidget(self.colorButton, 1, 2) layout.addWidget(self.deleteButton, 1, 3) self.colorButton.clicked.connect(self.showColorDialog) self.deleteButton.clicked.connect(self.deleteNode) self.setLayout(layout)