TransWikia.com

How to Group Parameters in PyQGIS Processing Plugin

Geographic Information Systems Asked by Joshua Evans on December 31, 2020

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?

One Answer

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)

Answered by etrimaille on December 31, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP