4

The PyQGIS Processing Plugin I'm writing has a lot of parameters, most of which are advanced and won't be necessary for most users. I'm concerned that a user will be confused if they see all these parameters that they don't know what to do with. Is there a way I can group parameters in a collapseable "advanced parameters" box in the plugin's GUI similarly to how the 'Round raster' built-in processing program does?

1

2 Answers 2

6

It's not clear to me if you are using PyQGIS. It's not mentioned in your question. If you are using only the GUI, then it's only when you create a model, so when you add an input, you can choose if yes or not it's an advanced parameter.

If you are using PyQGIS, you can define with a "flag". In the initAlgorithm function of your script, for the specific parameter :

    param = QgsProcessingParameterString(
        self.NAME_OF_THE_PARAMETER,
        tr('Your label'),
        optional=False,
        defaultValue='If any default')

    # The line below will take default flags already there and adds the Advanced one

    param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
    self.addParameter(param)
1
  • I am using PyQGIS and clarified my question. Thanks for your help! Oct 29, 2020 at 3:49
3

I came to this question with high hopes for a more general solution to arranging large numbers of parameters in a PyQGIS Processing tool, but was disappointed by the focus on exposing the 'Advanced Parameters' group.

Whilst 'Advanced Parameters' has been covered in the answer from @etrimaille I'll add another tip that I have found more generally useful, that the parameter label text will render HTML tags.

This allows elements to be added to simulate groups as follows:

From:

Plain parameter labels

To:

HTML tagged labels

The parameter text has been changed in the code as follows:

'Polygons Source' has become:

    '<br><b>INPUTS</b><br><br>Polygons Source'

'Output layer' has become:

    '<br><hr><b>OUTPUTS</b><br><br>Output layer'

The only downside that I have encountered to using this is that the output parameter text is used as a layer name if the output data type is left as temporary, resulting in an ugly layer name.

Your Answer

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

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