#include #include #include #include "tpixel.h" Tpixel::Tpixel( 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); MaxVal=255; } int Tpixel::value() { return val; } void Tpixel::paintEvent( QPaintEvent * ) { QString s = QString( "%1" ).arg((double)(val)); if(val==0) s= QString("n/c"); 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 Tpixel::setValue( int vall ) { val=vall; bgColor->setRgb((int)(((float)(val)/(float)(MaxVal))*255.),0,0); if(val>=MaxVal) bgColor->setRgb(0,255,255); //printf("%f\n",(((float)(val)/(float)(MaxVal)))); //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); }