QStatusbar formatting and designing

  • I took a look at QStatusBar and i found the Things i need for what i want to do. But at the Moment i stuck with 1 Thing. I want Notifications in my Statusbar if something was successfull or went wrong. For that i want different Messages. At this Point its no Problem to do that, but i have a Problem with formatting and designing that Message. For the first Purpose i want just a Green Background for something that went good and red for others. After that the Background Color disappears.

    I searched the Web for Solutions and some Guys took QTimers, but this wont work in binding with my needs. Anyone has good Ideas for that?

  • Hi! You said timers won't work for you. Please elaborate on this so we can find a solution that suits your needs. The following uses a timer and looks good to me so far.


    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <QTimer>
    namespace Ui {
    class MainWindow;
    class MainWindow : public QMainWindow
        explicit MainWindow(QWidget *parent = 0);
    private slots:
        void on_pushButton_clicked();
        void on_pushButton_2_clicked();
        Ui::MainWindow *ui;
        QTimer m_timer;
        void showStatusMessage(QString const &text, bool isOk);
        void onTimeout();
    #endif // MAINWINDOW_H


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QStatusBar>
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        connect(&m_timer, &QTimer::timeout, this, &MainWindow::onTimeout);
        delete ui;
    void MainWindow::showStatusMessage(const QString &text, bool isOk)
        if (isOk)
           ui->statusBar->setStyleSheet("background-color: rgb(0, 255, 0); color: black");
           ui->statusBar->setStyleSheet("background-color: rgb(255, 0, 0); color: black");
    void MainWindow::onTimeout()
    void MainWindow::on_pushButton_clicked()
        showStatusMessage("Good", true);
    void MainWindow::on_pushButton_2_clicked()
        showStatusMessage("Not good", false);

  • oh thanks. looks like i used the timer wrong. this example helps me a lot.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.