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

object

customEvent

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

icon

rtype

QIcon

iconColor

Returns the directory's icon color.

init

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.

paramWidget

rtype

QWidget

pathShouldByMonitoredByDefault

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

receivers

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) object
Return type

object

customEvent(self, QEvent)
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

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

init(self)
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

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

receivers(self, PYQT_SIGNAL) int
sender(self) QObject
senderSignalIndex(self) int
setCustomColor(directory: str, color: Union[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: Union[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.