1

I am trying to implement the python code suggested as an answer to this question: QGIS Custom Form: “Other” category in combo box replaced by line edit [closed] I have the same goal as that question: to have an edit widget for data entry that starts as a dropdown menu (using value map) then change to a text line edit if the user selects "Other" from the menu. I am experienced with QGIS but new to python coding.

I put the code in a text editor and saved as FillForm.py. Then it seems I should in the layer properties type into the Init Function line edit: FillForm.formOpen. I went to the layer properties and couldn't find the Init function line edit. What should I do with this code to get QGIS to implement it?

My layer general properties look like this: enter image description here There isn't a text line edit called "Init function," so I don't know where to type FillForm.formOpen.

Instead I tried inputting the code as an action. enter image description here But when I select "Other" from the dropdown menu for the field "SiteName" it doesn't switch to a text edit line like I wanted it to. Now I have the option to run this action from the Identify Results menu enter image description here

Running the action gives me an error enter image description here

4
  • Your trying to use an action to listen for a drop down change on the SiteNamefield.currentIndexChaged.current(Other) field/control? I do not think actions are meant for that type of event listener functionality. Are you just wanting to get the value from the SiteNamefield within your action?
    – artwork21
    Nov 10, 2016 at 19:07
  • I'm trying to set up the data entry for the SiteName field. It is currently set up with a value map widget so that there is a dropdown menu to enter the site name. I want the value map widget to change to a text edit widget when I select the value "Other." I am completely new to using python in QGIS, and I cannot figure out where to put the code.
    – csk
    Nov 10, 2016 at 22:32
  • I'm not sure if that type of feature can be done in a python action (change ui control types from combo to text edit). However I do know it can be done if you create your own custom plugin/.ui and create the .ui in QT Designer and add the back end python logic for your desired control logic switch.
    – artwork21
    Nov 11, 2016 at 13:17
  • The other posts that I linked to suggested that I could save python code in a file next to the QGIS project and call that code by putting a function in a box called "Init function." The init function box is not where they said it would be; does it still exist in 2.16? Or is this a feature that has been removed?
    – csk
    Nov 11, 2016 at 17:08

1 Answer 1

0

Python init function was moved from layer general properties to layer field properties. This change happened in QGIS 2.14.enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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