python 3.x - PyQt 5.5 QML Combobox -
i'm trying play pyqt 5.5 using qml (installed source).
this main.qml
:
window { ... combobox { objectname: "cmbtypecompression" width: 240 height: 26 model: listmodel { id: cbitems listelement { text: "banana" } listelement { text: "apple" } listelement { text: "coconut" } } ... }
this code.py
class gui(qapplication): self.app = qapplication([]) self.engine = qqmlapplicationengine() self.ctx = self.engine.rootcontext() self.ctx.setcontextproperty("main", self.engine) self.engine.load(url) self.loadform() self.loadsignal() self.app.exec_() def loadsignal(self): obj = self.win.findchild(qobject, "btnsave") obj.messagerequired.connect(myfunction) def loadform(self): self.setprop("txtcompsub", "text", config.compression.sub_folder) self.setprop("txtnumprotos", "text", config.compression.num_prototype) self.setproplist("cmbtypecompression", "model", ["a", "b", "c"]) def setprop(self, objname, propname, value): obj = self.win.findchild(qobject, objname) property = qqmlproperty(obj, propname) property.write(value) def setproplist(self, objname, propname, values): obj = self.win.findchild(qobject, objname) property = qqmlproperty(obj, propname) property.setmodel #### <- ????????? ... ...
well, questions those:
- does exist better method load form?
with self.win.findchild(qobject, objname)
can qobject
not combobox
object.
- how can
combobox
object in qml file?
with property.read()
on combobox
(qobject
) qabstractlistmodel
object.
- how can set model of
combobox
object previous getting ofqobject
?
to put in simpler way:
how can set custom model in combobox
qml python , pyqt?
i found solution:
def loadform(self): ... self.setproplist("cmbtypecompression", "model", ["item a", "item b"]) def setproplist(self, objname, propname, values): obj = self.win.findchild(qobject, objname) property = qqmlproperty(obj, propname) property.write(values)
...but don't know if best solution
Comments
Post a Comment