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. [SOLVED] Setting 2 colors in Mainwindows Statusbar
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Setting 2 colors in Mainwindows Statusbar

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 6.5k 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.
  • W Offline
    W Offline
    Woody
    wrote on last edited by
    #1

    Hi all,

    I have a little issue and finding it hard to solve, if it is even possible to so.

    When I want to give a warning to the user, I want the statusbar to display a message in red like so:
    !http://wouterverbruggen.be/img/qt/red-status.jpg(Red status)!

    But when I want to give information it has to be black:
    !http://wouterverbruggen.be/img/qt/black-status.jpg(Black Status)!

    Is it possible to set a default color, and when I want to give a warning just change it?

    Thanks in advance.

    File not found. Nobody leave the room!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      Hi,
      I think if you are setting a QLabel to you statusbar then you can use "stylesheets":http://doc.qt.nokia.com/4.7-snapshot/stylesheet-examples.html for eg

      @QLabel *lblHello = new QLabel(this);
      lblHello->setText("Hi How are you");
      lblHello->setStyleSheet("QLabel { color: red;}");
      this->statusBar()->addPermanentWidget(lblHello,1);@

      This changes the color to red. So you can customize the color based on your requirement.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Woody
        wrote on last edited by
        #3

        That idd helped to solve the issue, I thank you for that!

        But how can you make it empty again after lets say 2sec?

        So if I give a warning it has to disappear after 2sec, how is that done then?

        File not found. Nobody leave the room!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          So you mean to say that the color should change after 2 sec or the message should also change i.e from waring to information ?

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Woody
            wrote on last edited by
            #5

            No, I want to make the statusbar empty, so nothing is showing. Show the warning for 2 sec and then make the statusbar empty again.

            File not found. Nobody leave the room!

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sam
              wrote on last edited by
              #6

              Well there is something like "showMessage":http://qt-project.org/doc/qt-4.8/qstatusbar.html#showMessage where you can set message as well as the timer. But I dont know whether it supports rich text or not.

              Other way you can use a QTimer eg.

              @QTimer *timer = new QTimer(this);
              connect(timer, SIGNAL(timeout()), this, SLOT(doSomething()));
              timer->start(1000);

              lblHello = new QLabel(this);
              lblHello->setText("Hi How are you");
              lblHello->setStyleSheet("QLabel { color: red;}");
              this->statusBar()->addPermanentWidget(lblHello,1);@

              and in the doSomething() slot you can remove your widget from the statusbar.

              Not yet tested!!! check if this works :)

              1 Reply Last reply
              0
              • W Offline
                W Offline
                Woody
                wrote on last edited by
                #7

                I was trying it with the timer. And that did the job.

                Solution:
                @m_timer = new QTimer(this);
                m_timer->setInterval(2000);

                connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));@
                

                Set my statusmessage:
                @m_warningLabel = new QLabel(this);
                m_warningLabel->setText(text);
                m_warningLabel->setStyleSheet("QLabel { color:red;}");

                ui->statusBar->addWidget(m_warningLabel, 0);
                
                m_timer->start();@
                

                on timerTimeout:
                @m_warningLabel->setVisible(false);
                m_timer->stop();@

                Thanks Soumitra!

                File not found. Nobody leave the room!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #8

                  You are welcome. :)

                  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