I'm adding some stuff to a QGIS plugin and trying to figure out how to work with user inputs. In this case, the user input is a string, which seems simple to work with, but I can't find an example of it anywhere.
I am not using Qt Designer to design my interface for the dialog box, I'm instead using various methods from the QgsProcessingParameters class. Specifically I am using QgsProcessingParameterString.
In the plugin, I'm using the initAlgorithm and adding a line for the user to input a string. Here is the code:
def initAlgorithm(self, config): #Add String as input self.addParameter( QgsProcessingParameterString( self.INPUT_TITLE, self.tr('Input title string (Optional)') ) )
Now in the processAlgorithm I use a method .parameterAsString
def processAlgorithm(self, parameters, context, feedback): """This actually does the processing for creating the print layout and exporting as .pdf""" log = feedback.setProgressText input_title = self.parameterAsString(parameters, self.INPUT_TITLE, context) log(print the user input)
I'm just trying to print the user input in this example. How do I get the value the user input (a string)? I want to create a variable which stores the user input as a string. I can use the string later in my program.
And are there any examples of using QgsProcessingAlgorithm.parameterAsString?