Hi everyone, I’m trying to change the color of a stylesheet every 2.5 seconds with a globale variable spread in other classes and a QTimer.
The change of color is supposed to be applied inside the slot. However, nothing change. Why? Someone has any idea?
Here is my code:
//StyleT.h
#include <QtGui>
class StyleT : public QMainWindow
{
Q_OBJECT
public:
StyleT();
static QString CoulorStyle;
public slots:
void TransitionStyle();
private:
QTimer *tempo;
};
//StyleT.cpp
#include <QtGui>
#include "StyleT.h"
#include "ClassA.h"
QString StyleT::CouleurStyle = "#F24C04";
StyleT::StyleT() : QMainWindow()
{
tempo = new QTimer(this);
QObject::connect(tempo, SIGNAL(timeout()), this, SLOT(TransitionStyle()));
tempo->start(2500);
}
void StyleT::TransitionStyle ()
{
if (CoulorStyle == "#F24C04")
{
CoulorStyle = "#00B4F9";
}
if (CoulorStyle == "#00B4F9")
{
CoulorStyle= "#F24C04";
}
}
//Classe A.cpp
#include <QtGui>
#include "StyleT.h"
#include "ClassA.h"
ClasseA::ClasseA() : QWidget ()
{
QLCDNumber *lcd = new QLCDNumber (this);
lcd->setSegmentStyle(QLCDNumber::Flat);
lcd->move(500,23);
lcd->display(75);
lcd->setStyleSheet("background-color:transparent; color:"+ StyleT::CoulorStyle + "; border: 2px solid white;");
}
//main
#include <QtGui>
#include "StyleT.h"
#include "ClassA.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
StyleT Window;
Window.show();
return app.exec();
}
↧