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

Methods

dismiss

Dismisses the item, removing it from the message bar and deleting it.

duration

Returns the duration (in seconds) of the message.

getStyleSheet

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

icon

Returns the icon for the message.

level

Returns the message level for the message.

setDuration

Sets the duration (in seconds) to show the message for.

setIcon

Sets the icon associated with the message.

setLevel

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

setText

Sets the message text to show in the item.

setTitle

Sets the title for in the item.

setWidget

Sets a custom widget to show in the item.

text

Returns the text for the message.

title

Returns the title for the message.

widget

Returns the widget for the message.

Signals

styleChanged

Emitted when the item's message level has changed and the message bar style will need to be updated as a result.

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(styleSheet: str)[source]

Emitted when the item’s message level has changed and the message bar style will need to be updated as a result.

Parameters:

styleSheet (str)

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]