[SOLVED] Setting 2 colors in Mainwindows Statusbar
-
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.
-
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.
-
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 :)
-
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!