Class: QgsMessageBar

class qgis.gui.QgsMessageBar(parent: QWidget = None)

Bases: PyQt5.QtWidgets.QFrame

Constructor for QgsMessageBar

A bar for displaying non-blocking messages to the user.

QgsMessageBar is a reusable widget which allows for providing feedback to users in a non-intrusive way. Messages are shown in a horizontal bar widget, which is styled automatically to reflect the severity (“message level”) of the displayed message (e.g. warning messages are styled in an orange color scheme, critical errors are shown in red, etc).

The message bar supports automatic stacking of multiple messages, so that only the most recent message is shown to users. Users can then manually dismiss individual messages to remove them from the stack, causing the next-most-recent message to be shown. If no messages are available to show then the message bar automatically hides.

The class also supports pushing custom widgets to the notification stack via the pushWidget() method.

Methods

actionEvent

changeEvent

childEvent

clearWidgets

Removes all items from the bar.

closeEvent

connectNotify

contextMenuEvent

create

createMessage

Creates message bar item widget containing a message text to be displayed on the bar.

currentItem

Returns the current visible item, or None if no item is shown.

customEvent

destroy

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

drawFrame

dropEvent

enterEvent

event

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hideEvent

initPainter

initStyleOption

inputMethodEvent

isSignalConnected

items

Returns a list of all items currently visible or queued for the bar.

keyPressEvent

keyReleaseEvent

leaveEvent

metric

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

param e

mouseReleaseEvent

moveEvent

nativeEvent

paintEvent

popWidget

Remove the specified item from the bar, and display the next most recent one in the stack.

pushCritical

Pushes a critical warning message with default timeout to the message bar.

pushInfo

Pushes a information message with default timeout to the message bar.

pushItem

Display a message item on the bar, after hiding the currently visible one and putting it in a stack.

pushMessage

A convenience method for pushing a message with the specified text to the bar.

pushSuccess

Pushes a success message with default timeout to the message bar.

pushWarning

Pushes a warning message with default timeout to the message bar.

pushWidget

Display a widget as a message on the bar, after hiding the currently visible one and putting it in a stack.

receivers

resizeEvent

sender

senderSignalIndex

sharedPainter

showEvent

tabletEvent

timerEvent

updateMicroFocus

wheelEvent

Signals

widgetAdded

Emitted whenever an item is added to the bar.

widgetRemoved

Emitted whenever an item was removed from the bar.

actionEvent(self, QActionEvent)
changeEvent(self, QEvent)
childEvent(self, QChildEvent)
clearWidgets(self) bool

Removes all items from the bar.

Return type

bool

Returns

True if all items were removed, False otherwise

closeEvent(self, QCloseEvent)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
createMessage(text: str, parent: QWidget = None) QgsMessageBarItem

Creates message bar item widget containing a message text to be displayed on the bar.

The caller takes ownership of the returned item.

Note

This is a low-level API call. Users are recommended to use the high-level pushMessage() API call instead.

createMessage(title: str, text: str, parent: QWidget = None) -> QgsMessageBarItem Creates message bar item widget containing a title and message text to be displayed on the bar.

The caller takes ownership of the returned item.

Note

This is a low-level API call. Users are recommended to use the high-level pushMessage() API call instead.

createMessage(widget: QWidget, parent: QWidget = None) -> QgsMessageBarItem Creates message bar item widget containing a custom widget to be displayed on the bar.

The caller takes ownership of the returned item.

Note

This is a low-level API call. Users are recommended to use the high-level pushWidget() API call instead.

Parameters
  • text (str) –

  • parent (QWidget = None) –

Return type

QgsMessageBarItem

currentItem(self) QgsMessageBarItem

Returns the current visible item, or None if no item is shown.

Return type

QgsMessageBarItem

customEvent(self, QEvent)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QDragEnterEvent)
dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
drawFrame(self, QPainter)
dropEvent(self, QDropEvent)
enterEvent(self, QEvent)
event(self, QEvent) bool
focusInEvent(self, QFocusEvent)
focusNextChild(self) bool
focusNextPrevChild(self, bool) bool
focusOutEvent(self, QFocusEvent)
focusPreviousChild(self) bool
hideEvent(self, QHideEvent)
initPainter(self, QPainter)
initStyleOption(self, QStyleOptionFrame)
inputMethodEvent(self, QInputMethodEvent)
isSignalConnected(self, QMetaMethod) bool
items(self) List[QgsMessageBarItem]

Returns a list of all items currently visible or queued for the bar.

New in version 3.14.

Return type

List[QgsMessageBarItem]

keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
leaveEvent(self, QEvent)
metric(self, QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, e: QMouseEvent)
Parameters

e (QMouseEvent) –

mouseReleaseEvent(self, QMouseEvent)
moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], sip.voidptr) Tuple[bool, int]
paintEvent(self, QPaintEvent)
popWidget(self, item: QgsMessageBarItem) bool

Remove the specified item from the bar, and display the next most recent one in the stack. If no messages remain in the stack, then the bar will be hidden.

Parameters

item (QgsMessageBarItem) – previously added item to remove.

Returns

True if item was removed, False otherwise

popWidget(self) -> bool Remove the currently displayed item from the bar and display the next item in the stack. If no remaining items are present, the bar will be hidden.

Return type

bool

Returns

True if the widget was removed, False otherwise

pushCritical(self, title: str, message: str)

Pushes a critical warning message with default timeout to the message bar.

Parameters
  • title (str) – title string for message

  • message (str) – The message to be displayed

New in version 2.8.

pushInfo(self, title: str, message: str)

Pushes a information message with default timeout to the message bar.

Parameters
  • title (str) – title string for message

  • message (str) – The message to be displayed

New in version 2.8.

pushItem(self, item: QgsMessageBarItem)

Display a message item on the bar, after hiding the currently visible one and putting it in a stack.

The message bar will take ownership of item.

Parameters

item (QgsMessageBarItem) –

pushMessage(self, text: str, level: Qgis.MessageLevel = Qgis.Info, duration: int = 5)

A convenience method for pushing a message with the specified text to the bar.

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

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.

pushMessage(self, title: str, text: str, level: Qgis.MessageLevel = Qgis.Info, duration: int = 5) A convenience method for pushing a message with the specified title and text to the bar.

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

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.

pushMessage(self, title: str, text: str, showMore: str, level: Qgis.MessageLevel = Qgis.Info, duration: int = 5) A convenience method for pushing a message with the specified title and text to the bar. Additional message content specified via showMore will be shown when the user presses a “more” button.

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

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.

Parameters
  • text (str) –

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

  • duration (int = 5) –

pushSuccess(self, title: str, message: str)

Pushes a success message with default timeout to the message bar.

Parameters
  • title (str) – title string for message

  • message (str) – The message to be displayed

New in version 2.8.

pushWarning(self, title: str, message: str)

Pushes a warning message with default timeout to the message bar.

Parameters
  • title (str) – title string for message

  • message (str) – The message to be displayed

New in version 2.8.

pushWidget(self, widget: QWidget, level: Qgis.MessageLevel = Qgis.Info, duration: int = 0) QgsMessageBarItem

Display a widget as a message on the bar, after hiding the currently visible one and putting it in a stack.

Parameters
  • widget (QWidget) – message widget to display

  • level (Qgis.MessageLevel = Qgis.Info) – is Qgis.Info, Warning, Critical or Success

  • duration (int = 0) – timeout duration of message in seconds, 0 value indicates no timeout (i.e. the message must be manually cleared by the user).

Return type

QgsMessageBarItem

receivers(self, PYQT_SIGNAL) int
resizeEvent(self, QResizeEvent)
sender(self) QObject
senderSignalIndex(self) int
sharedPainter(self) QPainter
showEvent(self, QShowEvent)
tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
updateMicroFocus(self)
wheelEvent(self, QWheelEvent)
widgetAdded

Emitted whenever an item is added to the bar. [signal]

Parameters

item (QgsMessageBarItem) –

widgetRemoved

Emitted whenever an item was removed from the bar. [signal]

Parameters

item (QgsMessageBarItem) –