Class: QgsMessageBarItem

Represents an item shown within a QgsMessageBar widget.

QgsMessageBarItem represents a single item (or message) which can be shown in a QgsMessageBar widget.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsMessageBarItem

Base classes

QWidget

QObject

QPaintDevice

class qgis.gui.QgsMessageBarItem[source]

Bases: QWidget

__init__(text: str | None, level: Qgis.MessageLevel = Qgis.MessageLevel.Info, duration: int = 0, parent: QWidget | None = None)

Constructor for QgsMessageBarItem, containing a message with the specified text to be displayed on the bar.

The level argument specifies the desired message level (severity) of the message, which controls how the message bar is styled when the item is displayed.

The optional duration argument can be used to specify the message timeout in seconds. If duration is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that the default timeout for the message level should be used.

Parameters:
  • text (Optional[str])

  • level (Qgis.MessageLevel = Qgis.MessageLevel.Info)

  • duration (int = 0)

  • parent (Optional[QWidget] = None)

__init__(title: str | None, text: str | None, level: Qgis.MessageLevel = Qgis.MessageLevel.Info, duration: int = 0, parent: QWidget | None = None)

Constructor for QgsMessageBarItem, containing a title and message with the specified text to be displayed on the bar.

The level argument specifies the desired message level (severity) of the message, which controls how the message bar is styled when the item is displayed.

The optional duration argument can be used to specify the message timeout in seconds. If duration is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that the default timeout for the message level should be used.

Parameters:
  • title (Optional[str])

  • text (Optional[str])

  • level (Qgis.MessageLevel = Qgis.MessageLevel.Info)

  • duration (int = 0)

  • parent (Optional[QWidget] = None)

__init__(title: str | None, text: str | None, widget: QWidget | None, level: Qgis.MessageLevel = Qgis.MessageLevel.Info, duration: int = 0, parent: QWidget | None = None)

Constructor for QgsMessageBarItem, containing a title, message with the specified text, and a custom widget to be displayed on the bar.

The level argument specifies the desired message level (severity) of the message, which controls how the message bar is styled when the item is displayed.

The optional duration argument can be used to specify the message timeout in seconds. If duration is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that the default timeout for the message level should be used.

Parameters:
  • title (Optional[str])

  • text (Optional[str])

  • widget (Optional[QWidget])

  • level (Qgis.MessageLevel = Qgis.MessageLevel.Info)

  • duration (int = 0)

  • parent (Optional[QWidget] = None)

__init__(widget: QWidget | None, level: Qgis.MessageLevel = Qgis.MessageLevel.Info, duration: int = 0, parent: QWidget | None = None)

Constructor for QgsMessageBarItem, containing a custom widget to be displayed on the bar.

The level argument specifies the desired message level (severity) of the message, which controls how the message bar is styled when the item is displayed.

The optional duration argument can be used to specify the message timeout in seconds. If duration is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that the default timeout for the message level should be used.

Parameters:
  • widget (Optional[QWidget])

  • level (Qgis.MessageLevel = Qgis.MessageLevel.Info)

  • duration (int = 0)

  • parent (Optional[QWidget] = None)

dismiss(self)[source]

Dismisses the item, removing it from the message bar and deleting it. Calling this on items which have not been added to a message bar has no effect.

Added in version 3.4.

duration(self) int[source]

Returns the duration (in seconds) of the message.

If the duration is 0 then the message will not automatically timeout and instead must be manually dismissed by the user.

See also

setDuration()

Return type:

int

getStyleSheet(self) str[source]

Returns the styleSheet which should be used to style a QgsMessageBar object when this item is displayed.

Return type:

str

icon(self) QIcon[source]

Returns the icon for the message.

See also

setIcon()

Return type:

QIcon

level(self) Qgis.MessageLevel[source]

Returns the message level for the message.

See also

setLevel()

Return type:

Qgis.MessageLevel

setDuration(self, duration: int) QgsMessageBarItem | None[source]

Sets the duration (in seconds) to show the message for. If duration is 0 then the message will not automatically timeout and instead must be manually dismissed by the user.

See also

duration()

Parameters:

duration (int)

Return type:

Optional[QgsMessageBarItem]

setIcon(self, icon: QIcon) QgsMessageBarItem | None[source]

Sets the icon associated with the message.

See also

icon()

Parameters:

icon (QIcon)

Return type:

Optional[QgsMessageBarItem]

setLevel(self, level: Qgis.MessageLevel) QgsMessageBarItem | None[source]

Sets the message level for the item, which controls how the message bar is styled when the item is displayed.

See also

level()

Parameters:

level (Qgis.MessageLevel)

Return type:

Optional[QgsMessageBarItem]

setText(self, text: str | None) QgsMessageBarItem | None[source]

Sets the message text to show in the item.

See also

text()

Parameters:

text (Optional[str])

Return type:

Optional[QgsMessageBarItem]

setTitle(self, title: str | None) QgsMessageBarItem | None[source]

Sets the title for in the item.

See also

title()

Parameters:

title (Optional[str])

Return type:

Optional[QgsMessageBarItem]

setWidget(self, widget: QWidget | None) QgsMessageBarItem | None[source]

Sets a custom widget to show in the item.

See also

widget()

Parameters:

widget (Optional[QWidget])

Return type:

Optional[QgsMessageBarItem]

signal styleChanged[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

text(self) str[source]

Returns the text for the message.

See also

setText()

Return type:

str

title(self) str[source]

Returns the title for the message.

See also

setTitle()

Return type:

str

widget(self) QWidget | None[source]

Returns the widget for the message.

See also

setWidget()

Return type:

Optional[QWidget]