Class: QgsDirectoryItem

class qgis.core.QgsDirectoryItem

Bases: QgsDataCollectionItem

A directory: contains subdirectories and layers

QgsDirectoryItem(parent: QgsDataItem, name: str, path: str) Constructor for QgsDirectoryItem, with the specified parent item.

The name argument specifies the text to show in the model for the item. This is usually the directory name, but in certain cases may differ for special directories (e.g. “Home”). If a non-directory-name text is used, it should be a translated string when appropriate.

The path argument specifies the directory path in the file system (e.g. “/home/gsherman/stuff”). A valid directory path must be specified.

QgsDirectoryItem(parent: QgsDataItem, name: str, dirPath: str, path: str, providerKey: str = ‘’) Constructor for QgsDirectoryItem, with the specified parent item.

The name argument specifies the text to show in the model for the item. This is usually the directory name, but in certain cases may differ for special directories (e.g. “Home”). If a non-directory-name text is used, it should be a translated string when appropriate.

The dirPath argument specifies the directory path in the file system (e.g. “/home/gsherman/stuff”). A valid directory path must be specified.

The path argument gives the item path in the browser tree. The path string can take any form, but is usually the same as dirPath or dirPath with a prefix, e.g. “favorites:/home/gsherman/Downloads”). QgsDirectoryItem items pointing to different dirPaths should always use a different item path.

The optional providerKey string can be used to specify the key for the QgsDataItemProvider that created this item.

Methods

childEvent

childrenCreated

connectNotify

createChildren

rtype:

List[QgsDataItem]

customEvent

deferredDelete

The item is scheduled to be deleted.

dirPath

Returns the full path to the directory the item represents.

directoryChanged

disconnectNotify

equal

param other:

hasDragEnabled

rtype:

bool

hiddenPath

Check if the given path is hidden from the browser model

homeDirIcon

Shared home directory icon.

icon

rtype:

QIcon

iconColor

Returns the directory's icon color.

isMonitored

Returns True if the directory is currently being monitored for changes and the item auto-refreshed when these occur.

isSignalConnected

mimeUris

rtype:

List[QgsMimeDataUtils.Uri]

monitoring

Returns the monitoring setting for this directory item.

monitoringForPath

Returns the monitoring setting for a directory path.

openDirIcon

Shared open directory icon.

paramWidget

rtype:

QWidget

pathShouldByMonitoredByDefault

Returns True if a directory path should be monitored by default.

populate

receivers

refresh

Refresh the items from a specified list of child items.

sender

senderSignalIndex

setCustomColor

Sets a custom icon color to use for the items for the corresponding directory path.

setIconColor

Sets the directory's icon color.

setMonitoring

Sets the monitoring setting for this directory.

setState

param state:

timerEvent

updateIcon

Will request a repaint of this icon.

childEvent(self, QChildEvent)
childrenCreated(self)
connectNotify(self, QMetaMethod)
createChildren(self) List[QgsDataItem]
Return type:

List[QgsDataItem]

customEvent(self, QEvent)
deferredDelete(self) bool

The item is scheduled to be deleted. E.g. if deleteLater() is called when item is in Populating state (createChildren() running in another thread), the deferredDelete() returns True and item will be deleted once Populating finished. Items with slow reateChildren() (for example network or database based) may check during createChildren() if deferredDelete() returns True and return from createChildren() immediately because result will be useless.

dirPath(self) str

Returns the full path to the directory the item represents.

Return type:

str

directoryChanged(self)
disconnectNotify(self, QMetaMethod)
equal(self, other: QgsDataItem) bool
Parameters:

other (QgsDataItem) –

Return type:

bool

hasDragEnabled(self) bool
Return type:

bool

hiddenPath(path: str) bool

Check if the given path is hidden from the browser model

Parameters:

path (str) –

Return type:

bool

homeDirIcon(fillColor: QColor | Qt.GlobalColor | QGradient = QColor(), strokeColor: QColor | Qt.GlobalColor | QGradient = QColor()) QIcon

Shared home directory icon.

Since QGIS 3.20 the optional fillColor and strokeColor arguments can be used to specify a fill and stroke color for the icon.

New in version 3.4.

icon(self) QIcon
Return type:

QIcon

iconColor(self) QColor

Returns the directory’s icon color.

An invalid color will be returned if the default icon color is used.

See also

setIconColor()

New in version 3.20.

Return type:

QColor

isMonitored(self) bool

Returns True if the directory is currently being monitored for changes and the item auto-refreshed when these occur.

New in version 3.20.

Return type:

bool

isSignalConnected(self, QMetaMethod) bool
mimeUris(self) List[QgsMimeDataUtils.Uri]
Return type:

List[QgsMimeDataUtils.Uri]

monitoring(self) Qgis.BrowserDirectoryMonitoring

Returns the monitoring setting for this directory item.

See also

setMonitoring()

New in version 3.20.

Return type:

Qgis.BrowserDirectoryMonitoring

monitoringForPath(path: str) Qgis.BrowserDirectoryMonitoring

Returns the monitoring setting for a directory path.

This method returns the monitoring setting for path only. If no explicit monitoring setting is in place for the path then Qgis.BrowserDirectoryMonitoring.Default is returned.

This method does not consider the monitoring setting of parent directories.

New in version 3.20.

Parameters:

path (str) –

Return type:

Qgis.BrowserDirectoryMonitoring

openDirIcon(fillColor: QColor | Qt.GlobalColor | QGradient = QColor(), strokeColor: QColor | Qt.GlobalColor | QGradient = QColor()) QIcon

Shared open directory icon.

Since QGIS 3.20 the optional fillColor and strokeColor arguments can be used to specify a fill and stroke color for the icon.

New in version 3.4.

paramWidget(self) QWidget
Return type:

QWidget

pathShouldByMonitoredByDefault(path: str) bool

Returns True if a directory path should be monitored by default.

In the absence of any other settings this will dictate whether the directory is monitored. This method does not consider an explicit monitoring setting set for the path, which can be determined by calling monitoringForPath().

All parent directories will be checked to determine whether they have monitoring manually enabled or disabled. As soon as a parent directory is found which has monitoring manually enabled or disabled then the corresponding value will be returned.

If no explicit setting is in place for a parent directory, then a check will be made to determine whether the path resides on a known slow drive. If so, monitoring is disabled by default and False will be returned. Otherwise paths are monitored by default and the function will return True.

See also

isMonitored()

See also

setMonitoring()

New in version 3.20.

Parameters:

path (str) –

Return type:

bool

populate(self, children: Iterable[QgsDataItem])
populate(self, foreground: bool = False) None
receivers(self, PYQT_SIGNAL) int
refresh(self, children: Iterable[QgsDataItem])

Refresh the items from a specified list of child items.

refresh(self)

sender(self) QObject
senderSignalIndex(self) int
setCustomColor(directory: str, color: QColor | Qt.GlobalColor | QGradient)

Sets a custom icon color to use for the items for the corresponding directory path.

If color is an invalid color then the default icon color will be used.

New in version 3.20.

Parameters:
  • directory (str) –

  • color (Union[QColor) –

setIconColor(self, color: QColor | Qt.GlobalColor | QGradient)

Sets the directory’s icon color.

Setting an invalid color will cause the default icon color to be used.

This is a transient property, and will not permanently alter the directory’s colors in future QGIS sessions. Use setCustomColor() to permanently set the directory’s color.

See also

iconColor()

New in version 3.20.

Parameters:

color (Union[QColor) –

setMonitoring(self, monitoring: Qgis.BrowserDirectoryMonitoring)

Sets the monitoring setting for this directory.

This is a persistent setting, which is saved in QSettings.

See also

monitoring()

New in version 3.20.

Parameters:

monitoring (Qgis.BrowserDirectoryMonitoring) –

setState(self, state: Qgis.BrowserItemState)
Parameters:

state (Qgis.BrowserItemState) –

timerEvent(self, QTimerEvent)
updateIcon(self)

Will request a repaint of this icon.

New in version 3.0.