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:

  1. does exist better method load form?

with self.win.findchild(qobject, objname) can qobject not combobox object.

  1. how can combobox object in qml file?

with property.read() on combobox (qobject) qabstractlistmodel object.

  1. how can set model of combobox object previous getting of qobject?

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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -