1

I want to open a form (made in QTDesign) in the layer action. It is possible?

2

Yes you can. Layer actions can call Python so you can do something like this:

from PyQt4 import uic
import os

uifile = r"{path to your UI file}\youruifile.ui"
uiinstance = uic.loadUi(uifile)
uiinstance.exec_()

enter image description here

You could even put that in a python file and call it rather then storing the code in the projet.

In yourcode.py

from PyQt4 import uic
import os

def loadUI():
    uifile = os.path.join(os.path.dirname(__file__) , 'youruifile.ui')
    uiinstance = uic.loadUi(uifile)
    uiinstance.exec_()

enter image description here

|improve this answer|||||
  • It's possible pass a variable value to the form? – user1573901 May 17 '13 at 15:16
  • Where I save the yourcode.py ? – user1573901 May 17 '13 at 15:43
  • Save yourcode.py anywhere Pyton can find it. This is can be in `.qgis2\python` or in the folder with the project. I tend to go with in the folder with the the project. – Nathan W May 17 '13 at 21:00
  • It give the message: module object has no attribute loadUi – user1573901 May 21 '13 at 11:39
  • how can I pass a value to a form? – user1573901 May 21 '13 at 11:47

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.