J'essaye d'implémenter un Delegate dans un TreeView. Le délégué se compose d'un LineEdit et un bouton:PyQt Delegate avec widget défini par l'utilisateur
class Ui_Data_Delegate(QWidget):
def __init__(self, *args, **kwargs):
super(Ui_Data_Delegate, self).__init__(*args, **kwargs)
self.setGeometry(QRect(10, 10, 271, 61))
self.horizontalLayout = QHBoxLayout(self)
self.lineEdit = QLineEdit(self)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.ToolButton = QToolButton(self)
self.ToolButton.setObjectName("ToolButton")
self.horizontalLayout.addWidget(self.ToolButton)
Dans la fonction createEditor j'appelle la classe Ui_Data_Delegate:
def createEditor(self, parent, option, index):
if type == UDF.DT_ResultsSelector:
editor = Ui_Data_Delegate(parent)
editor.ToolButton.released.connect(self.make_selection)
return editor
else:
return QStyledItemDelegate.createEditor(self, parent, option, index)
Mais je ne vois pas un éditeur dans le treeView:
Si je rate le paramètre parent:
def createEditor(self, parent, option, index):
if type == UDF.DT_ResultsSelector:
editor = Ui_Data_Delegate()
editor.ToolButton.released.connect(self.make_selection)
return editor
else:
return QStyledItemDelegate.createEditor(self, parent, option, index)
je reçois:
C'est presque correct, mais le widget doit apparaître dans la cellule Treeview!
Qu'est-ce que je fais mal?