使用minicom截图:#snapshot 1.png
可以看到效果图:

根据前一篇HELLO WORD的方法编译运行,记得在run-setting auguments上输入-qws
部分代码如下:
#include <QtGui>
#include "rgb_color.h"
//#include "qstring.h"
rgbDialog::rgbDialog( QWidget* parent)
:QDialog(parent)
{
setupUi(this);
Qt::WindowFlags flags=0;
flags |= Qt::WindowMaximizeButtonHint;//add max button
this->setWindowFlags(flags);//update()
// this is must be in
QObject::connect(RHSlider,SIGNAL(valueChanged(int)),
this,SLOT(setRValue()));
QObject::connect(GHSlider,SIGNAL(valueChanged(int)),
this,SLOT(setGValue()));
QObject::connect(BHSlider,SIGNAL(valueChanged(int)),
this,SLOT(setBValue()));
QObject::connect(shapecomboBox,SIGNAL(activated(int)),
this,SLOT(setShape(int)));//shapecomboBox
QObject::connect(stylecomboBox,SIGNAL(activated(int)),
this,SLOT(setStyle(int)));
//SIGNAL AND SLOT
rValue = 0;
gValue = 0;
bValue = 0;
myShape = 0;
myStyle = 0;
//*****MAIN CODE***
setStyleSheet("background:rgb(200,255,255)");
this->ssgroupBox->setStyleSheet("background:rgb(200,255,255)");
this->Rlabel->setStyleSheet("background-color: rgb(200,255,255)");
this->Glabel->setStyleSheet("background:rgb(200,255,255)");
this->Blabel->setStyleSheet("background:rgb(200,255,255)");
this->RHSlider->setStyleSheet("background:rgb(200,255,255)");
this->GHSlider->setStyleSheet("background:rgb(200,255,255)");
this->BHSlider->setStyleSheet("background:rgb(200,255,255)");
redLCDNumber->setStyleSheet("background:rgb(255, 0, 0)");
greenLCDNumber->setStyleSheet("background:rgb(0, 255, 0)");
blueLCDNumber->setStyleSheet("background:rgb(0, 0, 255)");
this->pixmaplabel->clear();
pixmaplabel->setPalette( QPalette( QColor(192, 192, 192) ) );
pixmaplabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
pixmaplabel->setAlignment(Qt::AlignCenter);
pixmaplabel->setText( "Designed By XPH \n2-9-2010" );
rgbColor.setRgb(0,0,0);
}
void rgbDialog::paintEvent( QPaintEvent * )
{
QPainter paint(this);
paint.setPen(QPen(Qt::black,1,Qt::SolidLine));
if(myStyle == 0)
paint.setBrush(QBrush(rgbColor,Qt::SolidPattern));
else if(myStyle == 1)
paint.setBrush(QBrush(rgbColor,Qt::Dense4Pattern));
else if(myStyle == 2)
paint.setBrush(QBrush(rgbColor,Qt::HorPattern));
else if(myStyle == 3)
paint.setBrush(QBrush(rgbColor,Qt::VerPattern));
else if(myStyle == 4)
paint.setBrush(QBrush(rgbColor,Qt::BDiagPattern));
else if(myStyle == 5)
paint.setBrush(QBrush(rgbColor,Qt::CrossPattern));
else if(myStyle == 6)
paint.setBrush(QBrush(rgbColor,Qt::DiagCrossPattern));
if(myShape == 0)
paint.drawEllipse(10,10,100,80);//center int x, int y, int width ,int high
else if(myShape == 1)
paint.drawRoundRect(10,10,100,80,25,25);
else if(myShape == 2)
paint.drawPie(10,10,100,100,45*16,270*16);
else if(myShape == 3)
{
//QPointArray a; //USE IN QT3
QPolygon a; //qt4 USE THIS
a.setPoints(11,60,10,110,40,80,40,110,70,75,70,75,110,45,110,45,70,10,70,40,40,10,40);
//have 11 points
paint.drawPolygon(a);
}
}
void rgbDialog::setRValue()
{
rValue = RHSlider->value();
redLCDNumber->display(rValue);
QString text=tr("%1%2%3")
.arg("background:rgb(")
.arg(rValue)
.arg(", 0, 0)");
//setWindowTitle(text);//DEBUG
redLCDNumber->setStyleSheet(text);
rgbColor.setRgb(rValue,gValue,bValue);
update();
}
void rgbDialog::setGValue()
{
gValue = GHSlider->value();
greenLCDNumber->display(gValue);
QString text=tr("%1%2%3")
.arg("background:rgb(0,")
.arg(gValue)
.arg(", 0)");
//setWindowTitle(text);
greenLCDNumber->setStyleSheet(text);
rgbColor.setRgb(rValue,gValue,bValue);
update();
}
void rgbDialog::setBValue()
{
bValue = BHSlider->value();
blueLCDNumber->display(bValue);
QString text=tr("%1%2%3")
.arg("background:rgb(0, 0,")
.arg(bValue)
.arg(")");
//setWindowTitle(text);
blueLCDNumber->setStyleSheet(text);
rgbColor.setRgb(rValue,gValue,bValue);
update();
}
void rgbDialog::setStyle(int index)
{
if(index == 0)
myStyle = 0;
else if(index == 1)
myStyle = 1;
else if(index == 2)
myStyle = 2;
else if(index == 3)
myStyle = 3;
else if(index == 4)
myStyle = 4;
else if(index == 5)
myStyle = 5;
else if(index == 6)
myStyle = 6;
update();
}
void rgbDialog::setShape(int index)
{
if(index == 0)
myShape = 0;
else if(index == 1)
myShape = 1;
else if(index == 2)
myShape = 2;
else if(index == 3)
myShape = 3;
update();
}