QStatusBar Class
The QStatusBar class is a bar for messages and small widgets at the bottom of a window. More…
| Header | #include <QStatusBar> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
List of all members, including inherited members
Public Functions
| QStatusBar(QWidget *parent = nullptr) | |
| ~QStatusBar() | |
| void | addWidget(QWidget *widget, int stretch = 0) |
| void | insertWidget(int index, QWidget *widget, int stretch = 0) |
| void | addPermanentWidget(QWidget *widget, int stretch = 0) |
| void | insertPermanentWidget(int index, QWidget *widget, int stretch = 0) |
| void | removeWidget(QWidget *widget) |
| QString | currentMessage() const |
| bool | isSizeGripEnabled() const |
| void | setSizeGripEnabled(bool enabled) |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Public Slots
| void | showMessage(const QString &text, int timeout = 0) |
| void | clearMessage() |
Signals
| void | messageChanged(const QString &message) |
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
| void | resizeEvent(QResizeEvent *event) |
| void | timerEvent(QTimerEvent *event) |
| void | changeEvent(QEvent *event) |
Detailed Description
A status bar shows a message, which goes away after a time or when it is cleared, and has widgets: the ones that addWidget() adds are on the left and hidden while a message is shown, and the ones that addPermanentWidget() adds are on the right and always there:
QStatusBar *bar = new QStatusBar(window);
bar->addPermanentWidget(new QLabel("Line 1, column 1"));
bar->showMessage("File saved", 3000);
A status bar with a message, and one with a widget on each side.

See also QLabel and QProgressBar.
Differences from Qt
There is no QMainWindow to have a status bar, so put it at the bottom of a layout. The size grip is not drawn: setSizeGripEnabled() is only a property. There is no reformat() and no hideOrShow(), and a message cannot be set by a QWidget::statusTip.
Member Function Documentation
QStatusBar::QStatusBar(QWidget *parent = nullptr)
Constructs a status bar with no message and the given parent. It is as high as its widgets need, and as wide as its parent.
QStatusBar::~QStatusBar()
Destroys the status bar.
void QStatusBar::addPermanentWidget(QWidget *widget, int stretch = 0)
Adds widget on the right, after the ones that are there, with the stretch factor. It is not hidden by a message.
See also insertPermanentWidget() and addWidget().
void QStatusBar::addWidget(QWidget *widget, int stretch = 0)
Adds widget on the left, after the ones that are there, with the stretch factor that says how much of the extra room it takes. It is hidden while a message is shown. The status bar makes it a child.
See also insertWidget() and addPermanentWidget().
void QStatusBar::changeEvent(QEvent *event)
Reimplements QWidget::changeEvent().
void QStatusBar::clearMessage()
Removes the message, and shows the widgets on the left again. Emits messageChanged() if there was a message.
See also showMessage().
QString QStatusBar::currentMessage() const
Returns the message that is shown, or an empty text if there is none.
See also showMessage().
void QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch = 0)
Inserts widget among the widgets on the right, at index, with the given stretch factor.
See also addPermanentWidget().
void QStatusBar::insertWidget(int index, QWidget *widget, int stretch = 0)
Inserts widget among the widgets on the left, at index, with the given stretch factor.
See also addWidget().
bool QStatusBar::isSizeGripEnabled() const
Returns the size grip property, false by default. It has no effect.
void QStatusBar::messageChanged(const QString &message)
This signal is emitted when the message changes to message, which is empty when it is cleared.
QSize QStatusBar::minimumSizeHint() const
Reimplements QWidget::minimumSizeHint().
void QStatusBar::paintEvent(QPaintEvent *event)
Reimplements QWidget::paintEvent().
void QStatusBar::removeWidget(QWidget *widget)
Removes widget from the status bar. It is not deleted, and is hidden; it stays a child.
See also addWidget().
void QStatusBar::resizeEvent(QResizeEvent *event)
Reimplements QWidget::resizeEvent().
void QStatusBar::setSizeGripEnabled(bool enabled)
Sets the size grip property to enabled. It has no effect.
void QStatusBar::showMessage(const QString &text, int timeout = 0)
Shows text in the status bar in place of the widgets on the left. If timeout is more than 0, the message goes away after that many milliseconds; otherwise it stays until clearMessage() or another message. Emits messageChanged().
See also clearMessage().
QSize QStatusBar::sizeHint() const
Reimplements QWidget::sizeHint().
void QStatusBar::timerEvent(QTimerEvent *event)
Reimplements QWidget::timerEvent().