#include #include #include #include "tempsens.h" Tempsens::Tempsens( QWidget *parent ) : QWidget( parent) { //setPalette( QPalette( QColor( 250, 250, 200) ) ); //this->setPalette( QPalette( QColor( 250, 250, 200) ) ); bgColor= new QColor(200,200,200); this->setAutoFillBackground (1); } float Tempsens::value() { return val; } void Tempsens::paintEvent( QPaintEvent * ) { QString s = QString( "%1c" ).arg((double)(val),0,'g',3); QFont sansFont( "Helvetica [Cronyx]", 12 ); QPainter p( this ); p.setFont(sansFont); p.setPen(Qt::white); int width=this->width(); int height=this->height(); p.drawText(width/4 , height/2, s ); } void Tempsens::setValue( float vall ) { val=vall; int rred= (int)(((float)(val-MinVal)/(float)(MaxVal-MinVal))*255.); int bblue=255-(int)(((float)(val-MinVal)/(float)(MaxVal-MinVal))*255.); //printf("%d \n",val); bgColor->setRgb(rred,0,bblue); //QPalette::ColorRole QPalette *mypalette=new QPalette(); // mypalette->setColor ( mypalette->Base, *bgColor ); mypalette->setColor ( mypalette->Base, Qt::red); //this->setBackgroundRole (mypalette->Shadow); //this->setBackgroundColor(*bgColor); repaint(); this->setPalette( QPalette( *bgColor ) ); emit valueChanged(val); }