Class: QgsDataSourceSelectWidget

The QgsDataSourceSelectWidget class embeds the browser view to select an existing data source.

By default any layer type can be chosen, the valid layer type can be restricted by setting a layer type filter with setLayerTypeFilter(layerType) or by activating the filter directly from the constructor.

To retrieve the selected data source, uri() can be called and it will return a (possibly invalid) QgsMimeDataUtils.Uri.

Added in version 3.14.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsDataSourceSelectWidget

Base classes

QgsPanelWidget

Base class for any widget that can be shown as a inline panel

QWidget

QObject

QPaintDevice

Methods

expandPath

Expands out a file path in the view.

setCaseSensitive

Sets filter case sensitivity

setDescription

Sets a description label

setFilter

Apply filter to the model

setFilterSyntax

Sets filter syntax

setLayerTypeFilter

Sets layer type filter to layerType and activates the filtering

showEvent

Scroll to last selected index and expand it's children

showFilterWidget

Show/hide filter widget

uri

Returns the (possibly invalid) uri of the selected data source

Signals

itemTriggered

Emitted when an item is triggered, e.g. via a double-click.

selectionChanged

Emitted when the current selection changes in the widget.

validationChanged

This signal is emitted whenever the validation status of the widget changes.

class qgis.gui.QgsDataSourceSelectWidget[source]

Bases: QgsPanelWidget

__init__(browserModel: QgsBrowserGuiModel | None = None, setFilterByLayerType: bool = False, layerType: Qgis.LayerType = Qgis.LayerType.Vector, parent: QWidget | None = None)

Constructs a QgsDataSourceSelectWidget, optionally filtering by layer type

Parameters:
  • browserModel (Optional[QgsBrowserGuiModel] = None) – an existing browser model (typically from app), if None an instance will be created

  • setFilterByLayerType (bool = False) – activates filtering by layer type

  • layerType (Qgis.LayerType = Qgis.LayerType.Vector) – sets the layer type filter, this is in effect only if filtering by layer type is also active

  • parent (Optional[QWidget] = None) – the object

expandPath(self, path: str | None, selectPath: bool = False)[source]

Expands out a file path in the view.

The path must correspond to a valid directory existing on the file system.

Since QGIS 3.38 the selectPath argument can be used to automatically select the path too.

Added in version 3.28.

Parameters:
  • path (Optional[str])

  • selectPath (bool = False)

signal itemTriggered(uri: QgsMimeDataUtils.Uri)[source]

Emitted when an item is triggered, e.g. via a double-click.

Parameters:

uri (QgsMimeDataUtils.Uri)

signal selectionChanged[source]

Emitted when the current selection changes in the widget.

setCaseSensitive(self, caseSensitive: bool)[source]

Sets filter case sensitivity

Parameters:

caseSensitive (bool)

setDescription(self, description: str | None)[source]

Sets a description label

Parameters:

description (Optional[str]) – a description string

Note

the description will be displayed at the bottom of the dialog

Added in version 3.8.

setFilter(self)[source]

Apply filter to the model

setFilterSyntax(self, a0: QAction | None)[source]

Sets filter syntax

Parameters:

a0 (Optional[QAction])

setLayerTypeFilter(self, layerType: Qgis.LayerType)[source]

Sets layer type filter to layerType and activates the filtering

Parameters:

layerType (Qgis.LayerType)

showEvent(self, e: QShowEvent | None)[source]

Scroll to last selected index and expand it’s children

Parameters:

e (Optional[QShowEvent])

showFilterWidget(self, visible: bool)[source]

Show/hide filter widget

Parameters:

visible (bool)

uri(self) QgsMimeDataUtils.Uri[source]

Returns the (possibly invalid) uri of the selected data source

Return type:

QgsMimeDataUtils.Uri

signal validationChanged(isValid: bool)[source]

This signal is emitted whenever the validation status of the widget changes.

Parameters:

isValid (bool) – True if the current status of the widget is valid