QgsMapLayerComboBox class

The QgsMapLayerComboBox class is a combo box which displays the list of layers.

Constructors, destructors, conversion operators

QgsMapLayerComboBox(QWidget* parent = nullptr) explicit
QgsMapLayerComboBox creates a combo box to display the list of layers (currently in the registry).

Public functions

auto additionalItems() const -> QStringList
Returns the list of additional (non map layer) items included at the end of the combo box.
auto allowEmptyLayer() const -> bool
Returns true if the combo box allows the empty layer ("not set") choice.
auto currentLayer() const -> QgsMapLayer*
Returns the current layer selected in the combo box.
auto exceptedLayerList() const -> QList<QgsMapLayer*>
returns the list of excepted layers
auto excludedProviders() const -> QStringList
Returns the list of data providers which are excluded from the combobox.
auto filters() const -> QgsMapLayerProxyModel::Filters
currently used filter on list layers
auto layer(int layerIndex) const -> QgsMapLayer*
Returns the layer currently shown at the specified index within the combo box.
void setAdditionalItems(const QStringList& items)
Sets a list of additional (non map layer) items to include at the end of the combobox.
void setAllowEmptyLayer(bool allowEmpty)
Sets whether an optional empty layer ("not set") option is shown in the combo box.
void setExceptedLayerList(const QList<QgsMapLayer*>& layerList)
except a list of layers not to be listed
void setExcludedProviders(const QStringList& providers)
Sets a list of data providers which should be excluded from the combobox.
void setFilters(QgsMapLayerProxyModel::Filters filters)
setFilters allows fitering according to layer type and/or geometry type.
void setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the combo box text.
auto showCrs() const -> bool
Returns true if the combo box shows the layer's CRS.

Signals

void layerChanged(QgsMapLayer* layer)
layerChanged this signal is emitted whenever the currently selected layer changes

Public slots

void setLayer(QgsMapLayer* layer)
setLayer set the current layer selected in the combo

Function documentation

QgsMapLayerComboBox::QgsMapLayerComboBox(QWidget* parent = nullptr) explicit

QgsMapLayerComboBox creates a combo box to display the list of layers (currently in the registry).

The layers can be filtered and/or ordered.

QStringList QgsMapLayerComboBox::additionalItems() const

Returns the list of additional (non map layer) items included at the end of the combo box.

bool QgsMapLayerComboBox::allowEmptyLayer() const

Returns true if the combo box allows the empty layer ("not set") choice.

QgsMapLayer* QgsMapLayerComboBox::currentLayer() const

Returns the current layer selected in the combo box.

QStringList QgsMapLayerComboBox::excludedProviders() const

Returns the list of data providers which are excluded from the combobox.

QgsMapLayer* QgsMapLayerComboBox::layer(int layerIndex) const

Returns the layer currently shown at the specified index within the combo box.

Parameters
layerIndex position of layer to return

void QgsMapLayerComboBox::setAdditionalItems(const QStringList& items)

Sets a list of additional (non map layer) items to include at the end of the combobox.

These may represent additional layers such as layers which are not included in the map layer registry, or paths to layers which have not yet been loaded into QGIS.

void QgsMapLayerComboBox::setAllowEmptyLayer(bool allowEmpty)

Sets whether an optional empty layer ("not set") option is shown in the combo box.

void QgsMapLayerComboBox::setExcludedProviders(const QStringList& providers)

Sets a list of data providers which should be excluded from the combobox.

void QgsMapLayerComboBox::setShowCrs(bool showCrs)

Sets whether the CRS of layers is also included in the combo box text.

bool QgsMapLayerComboBox::showCrs() const

Returns true if the combo box shows the layer's CRS.