2

How can I include a form created in Designer in my QGIS plugin?

And how to get controls values (textbox,label,etc)?

2

One approach is to load the .ui file dynamically:

    # load the form
    path = os.path.dirname( os.path.abspath( __file__ ) )
    self.optionsDialog = uic.loadUi(os.path.join(path,"options.ui"))

    # restore some options
    self.optionsDialog.spinBoxFrameLength.setValue(2)
    self.optionsDialog.checkBoxBackwards.setChecked(True)

    # show dialog
    self.optionsDialog.show()

You can have a look at the corresponding full source code here: https://github.com/anitagraser/TimeManager/blob/master/timemanagerguicontrol.py

  • Thank you! I was able to download the form, but I do not understand how can I assign, for example, a textBrowser value? – Cathrin Jun 21 '12 at 10:01
  • As posted in the example above: There most likely is a .setValue() function. You have to assign names to the UI parts in Designer, like "spinBoxFrameLength" in the example. – underdark Jun 22 '12 at 6:41
  • I can not find where the assigned value "spinBoxFrameLength". <<self.optionsDialog.spinBoxFrameLength.setValue(animationFrameLength) >> is it? what value it takes in this case? – Cathrin Jun 22 '12 at 6:46
  • I have an error occurs. swears at "setValue" . << AttributeError: 'QTextBrowser' object has no attribute 'setValue' >> – Cathrin Jun 22 '12 at 6:52
  • 1
    QTextBrowser has a setDocument() function. If you want to write plugins you will have to learn to use the Qt documentation doc.qt.nokia.com/4.7-snapshot/qtextbrowser.html – underdark Jun 22 '12 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.