I finally managed to make it working! Your code is exactly the same as I tried before my last post and I did not manage to make it working because of a recursivity problem (the sigDataChanged signal was directly emitted in the setColor method).
I had to change a little bit the code :
sigDataChanged = pyqtSignal(str)
def __init__(self, color=None):
some python code here
self.btnColor.clicked.connect(self.changeColor)
def changeColor(self):
colorInit.setNamedColor(self._color)
color
= QColorDialog.
getColor(colorInit, self,
"Select a color") if color.isValid():
self.ldtColor.setText(color.name())
self.setColor(color.name())
self.sigDataChanged.emit(self._color)
def updateIcon(self):
newcolor.setNamedColor(self._color)
pixmap.fill(newcolor)
self.btnColor.setIcon(icon)
def getColor(self):
return self._color
def setColor(self, newColor):
self._color = newColor
self.ldtColor.setText(newColor)
self.updateIcon()
color = pyqtProperty(str, fget=getColor, fset=setColor)
class ColorWidget(QWidget):
sigDataChanged = pyqtSignal(str)
def __init__(self, color=None):
some python code here
self.btnColor.clicked.connect(self.changeColor)
def changeColor(self):
colorInit = QColor()
colorInit.setNamedColor(self._color)
color = QColorDialog.getColor(colorInit, self, "Select a color")
if color.isValid():
self.ldtColor.setText(color.name())
self.setColor(color.name())
self.sigDataChanged.emit(self._color)
def updateIcon(self):
pixmap = QPixmap(24, 24)
newcolor = QColor()
newcolor.setNamedColor(self._color)
pixmap.fill(newcolor)
icon = QIcon(pixmap)
self.btnColor.setIcon(icon)
def getColor(self):
return self._color
def setColor(self, newColor):
self._color = newColor
self.ldtColor.setText(newColor)
self.updateIcon()
color = pyqtProperty(str, fget=getColor, fset=setColor)
To copy to clipboard, switch view to plain text mode
I just emit the sigDataChanged signal after the setColor method has been called. Finally, I update the model by connecting this signal to the submit slot of the QDataWidgetMapper in the appropriate PropertiesEditor class (as you mentionned).
self.colorWidget.sigDataChanged.connect(self.dataMapper.submit)
self.colorWidget.sigDataChanged.connect(self.dataMapper.submit)
To copy to clipboard, switch view to plain text mode
Problem solved. I close the thread.
Thank you very much anda_skoa for your time and help
.
Cheers,
Vincent
Bookmarks