Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

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

share|improve this question
add comment

1 Answer

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

share|improve this answer
    
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
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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