Change color of labels in status Bar
I wouldl like to change the color of a label in the statusBar
Code:
statusLabelWarning
= new QLabel;
statusLabelWarning->setPixmap( warningPixmap);
warningPixmap is a member variable.
When I need to change the color
Code:
statusLabelWarning->setText(tr("Rad. stimata"));
warningPixmap.fill(Qt::red);
but nothing happens.
I am missing something?
G
Re: Change color of labels in status Bar
try to reset this pixmap to a lable.
Re: Change color of labels in status Bar
How?
What do you mean to reset the QPixmap to a label?
G
Re: Change color of labels in status Bar
like this
Code:
...
statusLabelWarning->setText(tr("Rad. stimata"));
warningPixmap.fill(Qt::red);
statusLabelWarning->setPixmap( warningPixmap);
...
Re: Change color of labels in status Bar
First of all I think that setting text:
Code:
statusLabelWarning->setText(tr("Rad. stimata"));
clears the pixmap in label. If not, you are filling the pixmap, which is not that one in your label. In both cases you have to set it again, as my preposter said. Other way is to get your pixmap directly from label:
Code:
const_cast<QPixmap*>(statusLabelWarning->pixmap())->fill(Qt::red);
P.S. As it stands in docs: "Setting the pixmap clears any previous content."
Re: Change color of labels in status Bar - nothing
I am afraid to say that your solutions do not work.
The fact that the label is in the statusBar might be a problem?
I tried both solution to change the color of the label in the statusBar, but noting happen.
The same happen if I want to change the color of a label in a QToolBox.
Code:
{
s.setPalette(palette);
//qDebug()<<"Colore.."<<s.palette()<<color;
}
With this code nothing happen if the label is on a QToolBox. Nice if label is inside a standard QWidget....:confused:
Re: Change color of labels in status Bar
could you prepare compilable example with the problem?
1 Attachment(s)
Re: Change color of labels in status Bar
ok I've just tested 2 solutions. Here is the code:
Code:
#include <QtGui/QApplication>
#include <QMainWindow>
#include <QStatusBar>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
{
Q_OBJECT
public:
{
setCentralWidget(button);
pm.fill(Qt::black);
statusBar()->addPermanentWidget(label);
label->setPixmap(pm);
connect(button, SIGNAL(clicked()), this, SLOT(slot_clicked()));
}
private:
int way;
private slots:
void slot_clicked()
{
if (way == 1) // <- first way to change color
{
pm.fill(Qt::red);
label->setPixmap(pm);
way = 2;
return;
}
if (way == 2) // <- second way
{
const_cast<QPixmap*>(label->pixmap())->fill(Qt::black);
label->update();
way = 1;
}
}
};
int main(int argc, char *argv[])
{
MainWindow w(1);
w.show();
return a.exec();
}
#include "main.moc"
In this app when you click on button "RED" the label in statusBar changes it color from black to red or from red to black. In the first direction it's first way to do this, and in second it's second.
And here is screeshot:
Re: Change color of labels in status Bar
But if I wanna change also the text of the label along with the color?
It seems that subsequent change of the content of the lable delete the previous content...
Re: Change color of labels in status Bar
I think a better way is to change di background of the label:
Code:
{
s.setPalette(palette);
}
and
changeColor(myLabel,"red");