QgsMessageBar class

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

Public static functions

static auto createMessage(const QString& text, QWidget* parent = nullptr) -> QgsMessageBarItem*
make out a widget containing a message to be displayed on the bar
static auto createMessage(const QString& title, const QString& text, QWidget* parent = nullptr) -> QgsMessageBarItem*
make out a widget containing title and message to be displayed on the bar
static auto createMessage(QWidget* widget, QWidget* parent = nullptr) -> QgsMessageBarItem*
make out a widget containing title and message to be displayed on the bar

Constructors, destructors, conversion operators

QgsMessageBar(QWidget* parent = nullptr)
Constructor for QgsMessageBar.

Public functions

auto popWidget(QgsMessageBarItem* item) -> bool
Remove the passed widget from the bar (if previously added), then display the next one in the stack if any or hide the bar.
void pushItem(QgsMessageBarItem* item)
Display a message item on the bar after hiding the currently visible one and putting it in a stack.
void pushMessage(const QString& text, Qgis::MessageLevel level = Qgis::Info, int duration = 5)
convenience method for pushing a message to the bar
void pushMessage(const QString& title, const QString& text, Qgis::MessageLevel level = Qgis::Info, int duration = 5)
convenience method for pushing a message with title to the bar
void pushMessage(const QString& title, const QString& text, const QString& showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 5)
convenience method for pushing a message to the bar with a detail text which be shown when pressing a "more" button
auto pushWidget(QWidget* widget, Qgis::MessageLevel level = Qgis::Info, int duration = 0) -> QgsMessageBarItem*
Display a widget as a message on the bar after hiding the currently visible one and putting it in a stack.

Signals

void widgetAdded(QgsMessageBarItem* item)
emitted when a message widget is added to the bar
void widgetRemoved(QgsMessageBarItem* item)
emitted when a message widget was removed from the bar

Public slots

auto clearWidgets() -> bool
Remove all items from the bar's widget list.
auto popWidget() -> bool
Remove the currently displayed widget from the bar and display the next in the stack if any or hide the bar.
void pushCritical(const QString& title, const QString& message)
Pushes a critical warning with default timeout to the message bar.
void pushInfo(const QString& title, const QString& message)
Pushes a information message with default timeout to the message bar.
void pushSuccess(const QString& title, const QString& message)
Pushes a success message with default timeout to the message bar.
void pushWarning(const QString& title, const QString& message)
Pushes a warning with default timeout to the message bar.

Function documentation

bool QgsMessageBar::popWidget(QgsMessageBarItem* item)

Remove the passed widget from the bar (if previously added), then display the next one in the stack if any or hide the bar.

Parameters
item item to remove
Returns true if the widget was removed, false otherwise

void QgsMessageBar::pushItem(QgsMessageBarItem* item)

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

Parameters
item Item to display

The message bar will take ownership of the item.

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

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

Parameters
widget message widget to display
level is Qgis::Info, Warning, Critical or Success
duration timeout duration of message in seconds, 0 value indicates no timeout

bool QgsMessageBar::clearWidgets() public slot

Remove all items from the bar's widget list.

Returns true if all items were removed, false otherwise

bool QgsMessageBar::popWidget() public slot

Remove the currently displayed widget from the bar and display the next in the stack if any or hide the bar.

Returns true if the widget was removed, false otherwise

void QgsMessageBar::pushCritical(const QString& title, const QString& message) public slot

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

Parameters
title title string for message
message The message to be displayed

void QgsMessageBar::pushInfo(const QString& title, const QString& message) public slot

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

Parameters
title title string for message
message The message to be displayed

void QgsMessageBar::pushSuccess(const QString& title, const QString& message) public slot

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

Parameters
title title string for message
message The message to be displayed

void QgsMessageBar::pushWarning(const QString& title, const QString& message) public slot

Pushes a warning with default timeout to the message bar.

Parameters
title title string for message
message The message to be displayed