Is there a simple method in the QgsProcessingParameters class for a checkable combo box option?
I cant seem to find the function described in the offical documentation or figured out any alternative. Ideally I would need something along the lines of
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterCheckableComboBox...
Best Answer
I think that the
QgsProcessingParameterEnum
will be sufficient to do what you are are asking.Just pass a list of items to the
options
keyword argument andTrue
to theallowMultiple
argument to allow multiple selections. E.g.To retrieve the user selected options, use the following methods:
for a single option which returns an integer or
for multiple selections which returns a list of integers.
You can then use these integers as indexes to retrieve items from any iterable object. In the simple example below, I simply retrieved the string items from the original options list.
The resulting algorithm interface looks like this (click the
button to select):
Select one or more items:
Algorithm log:
Another option could be to create a custom widget wrapper inside your processing script and use a
QListWidget
with checkable items. An example of this is shown below:Resulting UI and algorithm log shown below:
References:
Processing script template for QGIS3
Adding a custom widget to a QGIS Processing script