#include #include #include #include "humidity.h" Humidity::Humidity( 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 Humidity::value() { return val; } void Humidity::paintEvent( QPaintEvent * ) { QString s = QString( "%1\%" ).arg((double)(val)); 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/3 , height/2, s ); } void Humidity::setValue( float vall ) { val=vall; int bblue= (int)(((float)(val-MinVal)/(float)(MaxVal-MinVal))*255.); //int white = 255-bblue; //int bblue=255-(int)(((float)(val-MinVal)/(float)(MaxVal-MinVal))*255.); //printf("%i %i\n",rred,bblue); bgColor->setRgb(255,bblue,0); //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); }