I have extended the UI file resulting from the Plugin builder with Qt Creator. Just added some checkboxes and a combobox, named layercombo to the form. The application is named jacktest.py. It uses an intermediate file jackdialog.py (generated from the plugin builder, left unchanged).
Compiled the UI file and the resource file. Then added some code to the plugin and tested this. It s no problem to get the available layer names in a QMessagebox. But how to add these to the combobox ? Should be simple, but no option succeeds in referencing the combobox.
错误消息: 属性错误: jacktest 实例没有属性层孔布 。
我最近尝试的结果是:
# run method that performs all the real work
def run(self):
# create and show the dialog
dlg = jacktestDialog()
# show the dialog
dlg.show()
result = dlg.exec_()
for layer in self.iface.legendInterface().layers():
if layer.type() == QgsMapLayer.VectorLayer:
QMessageBox.information( self.iface.mainWindow(), "Info", layer.name())
self.layercombo.Items.Insert(0, layer.name())
# See if OK was pressed
if result == 1:
# do something useful (delete the line containing pass and
# substitute with your code
pass