Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStatusbar formatting and designing
Forum Updated to NodeBB v4.3 + New Features

QStatusbar formatting and designing

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fuel
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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.

      mainwindow.h

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

      mainwindow.cpp

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QStatusBar>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          connect(&m_timer, &QTimer::timeout, this, &MainWindow::onTimeout);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      void MainWindow::showStatusMessage(const QString &text, bool isOk)
      {
          ui->statusBar->showMessage(text);
          if (isOk)
             ui->statusBar->setStyleSheet("background-color: rgb(0, 255, 0); color: black");
          else
             ui->statusBar->setStyleSheet("background-color: rgb(255, 0, 0); color: black");
          m_timer.start(1000);
      }
      
      void MainWindow::onTimeout()
      {
          ui->statusBar->setStyleSheet("");
      }
      
      void MainWindow::on_pushButton_clicked()
      {
          showStatusMessage("Good", true);
      }
      
      void MainWindow::on_pushButton_2_clicked()
      {
          showStatusMessage("Not good", false);
      }
      
      1 Reply Last reply
      3
      • F Offline
        F Offline
        Fuel
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved