Handling Status bar in Main Window

1. Introduction
Qt is a well defined and matured framework that you can realise, when you understand and use each and every small functionallty of the framework. Here I'm going to draw a line regarding the QStatusBar class, which is must-have feature for all desktop application.

2. QStatusBar Class
The QStatusBar class provides a horizontal bar suitable for presenting status information. Typically the status bar request will occure from QMainWindow Object. The QMainWindow provides the main window for an application with manu, tool bar and etc. The QMainWindow class contains a function called statusbar() that returns the object of the status bar for main window. This function creates and returns an empty status bar if the status bar does not exist.

Syntax:
QStatusBar * QMainWindow::statusBar() const

Example:
QStatusBar *sBar;
sBar = statusbar()->showMessage(tr("Ready"));

It is also possible to create your own status bar and attach to the main window like below:

Syntax:
void QMainWindow::setStatusBar(QStatusBar * statusbar)

Example:
QStatusBar *sBar = new QStatusBar;
setStatusBar(sBar);

3. Multipart Status Bar
Another important feature which we are going to discuss here is adding small widget into status bar that will give you the multipart status bar. Qt provides some of the small widget like QLabel, QProgressBar and etc. These small widget can add, insert or remove from the status bar.

Syntax:
void QStatusBar::addPermanentWidget(QWidget * widget, int stretch = 0)
void QStatusBar::addWidget(QWidget * widget, int stretch = 0)

int QStatusBar::insertPermanentWidget(int index, QWidget * widget, int stretch = 0)
int QStatusBar::insertWidget(int index, QWidget * widget, int stretch = 0)

void QStatusBar::removeWidget(QWidget * widget)

Example:

QLabel *m_statusLeft = new QLabel("Ready", this);
m_statusLeft->setFrameStyle(QFrame::Panel | QFrame::Sunken);
   
QLabel *m_statusMiddle = new QLabel("Middle", this);
m_statusMiddle->setFrameStyle(QFrame::Panel | QFrame::Sunken);

QLabel *m_statusSMiddle = new QLabel("Second Middle", this);
m_statusSMiddle->setFrameStyle(QFrame::Panel | QFrame::Sunken);

   
QLabel *m_statusRight = new QLabel(QDate::currentDate().toString("dd MMMM yyyy, ddd"), this);
m_statusRight->setFrameStyle(QFrame::Panel | QFrame::Sunken);
   
statusBar()->addPermanentWidget(m_statusLeft, 3);
statusBar()->addPermanentWidget(m_statusMiddle, 4);
statusBar()->insertPermanentWidget(1, m_statusSMiddle, 2);
statusBar()->addPermanentWidget(m_statusRight, 1);
statusBar()->removeWidget(m_statusMiddle);
4. Conclusion
This is not a full fledged tutorial for Status Bar in Qt, just as an introduction for the beginners.