ok I've just tested 2 solutions. Here is the 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"
#include <QtGui/QApplication>
#include <QMainWindow>
#include <QStatusBar>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(int w) : QMainWindow(), way(w)
{
label = new QLabel("text");
button = new QPushButton("RED");
setCentralWidget(button);
QPixmap pm(64, 16);
pm.fill(Qt::black);
statusBar()->addPermanentWidget(label);
label->setPixmap(pm);
connect(button, SIGNAL(clicked()), this, SLOT(slot_clicked()));
}
private:
QLabel * label;
QPushButton * button;
int way;
private slots:
void slot_clicked()
{
if (way == 1) // <- first way to change color
{
QPixmap pm(64, 16);
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[])
{
QApplication a(argc, argv);
MainWindow w(1);
w.show();
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
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:
Bookmarks