i looking clean way use multi line text edit in qstyleditemdelegate. createeditor implementation pretty straight forward returning qtextedit instance
def createeditor(self, parent, option, index): return qtgui.qtextedit("some text") but setmodeldata expects edit widget derived qwidget parameter instead of qtextedits base qscrollarea. qt documentation tells me (at least in pyqt doc) setmodeldata function tries data qwidget userdata field. without having edit widget derived qwidget there no option in setting data. throws attributeerror because can't find text() on editor.
is there proven way use non-qwidget editor? or missing widget that?
currently quick fixed issue instanciating qlineedit qtextedit data toplaintext() , passing setmodeldata. hacky!! use duck typing , implement text() method on qtextedit derivate. still not nice way, isn't it? way in c++?
so took time , digged deeper problem. there in fact multiple cleaner solutions:
implementing property got work implementing qproperty on subclass of
qtexteditaddstextproperty user property object. here code:class delegatabletextedit(qtgui.qtextedit): @pyqtproperty(str, user=true) def text(self): return self.toplaintext() @text.setter def text(self, text): self.settext(text)using factory there seems way solve using delegates
setdefaultfactory()method takesqitemeditorfactoryhas registered custom editor creator usingregistereditor()function. can register custom implementation ofqitemeditorcreatorbaseclass there has overridencreatewidgetmethod (and if neededvaluepropertynamefunction well). haven't tried 1 yet
i decided take first solution needs custom qtextedit , overriden createeditor() function. both should work in c++
Comments
Post a Comment