[Qgis-developer] add form elements dynamically - qgis python plugin
karsten at terragis.net
Tue Apr 5 03:33:29 EDT 2011
Hi I am a beginner with python , QGIS and pyQT.
I am working on a python plug-in and would like to populate dynamically a pyQT based QDialog form with combo boxes at runtime (the elements to be added are input via a config txt file that is read). Thus I would like to get hints how I can do this .
I have a a py file with the dialog form (streameditcustomformdialog.py):
from PyQt4 import QtCore, QtGui
from ui_streameditcustomform import Ui_StreamEditCustomForm
# create the dialog for zoom to point
def __init__(self, parent = None):
# Set up the user interface from Designer.
self.ui = Ui_StreamEditCustomForm()
and a routine that reads the config file and should populate the form with new comboxes:
# QgisMainWindow = qgis.utils.iface.mainWindow()
filename = QFileDialog.getOpenFileName(None, 'Open File', "C:/", \
"Text Files (*.txt *.csv)");
formconfig_input = open(filename, 'r') # input species info id , name for batch processing
formconfig_line = formconfig_input.readline() # read csv text file line
if not formconfig_line: break
formconfig_splitline = formconfig_line.split(',')
if len(formconfig_splitline) < 3:
QMessageBox.information(None,"A problem occured with your input file.", \
"The file you choose did not have the proper \n syntax or number of comma separated fields.")
fieldname1 = formconfig_splitline
fieldtype1 = formconfig_splitline
fieldlength1 = formconfig_splitline
QMessageBox.information(None,"Form Info:", \
fieldname1 + '\n' + fieldtype1 + '\n' + fieldlength1)
self.dlg = StreamEditCustomFormDialog()
#show the dialog
self.dlg.comboBoxNew = QtGui.QComboBox()
self.dlg.comboBoxNew.setItemText(1, QtGui.QApplication.translate("Form", "bw", None, QtGui.QApplication.UnicodeUTF8))
However I tried it above - the combo box does not appear on the form which is showing ok if I run the plugin, no error message ...but no combo box ...
What am I doing wrong?
Will this take care of layout management or how could I have the layout (e.g. size of form handled if many combo boxes are added ?
Terra GIS LTD
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Qgis-developer