Qt QPainter类 画板的使用



//头文件

void paintEvent(QPaintEvent *paintEven);


//

//Set Paint Test
void mouseWidget::paintEvent(QPaintEvent *paintEven)
{
	QPainter  painter(this);
	painter.setPen(QPen(QColor(255,0,0)));
	painter.setBrush(QBrush(QColor(0,255,0,255),Qt::BrushStyle::Dense3Pattern));
	painter.drawRect(0,50,200,50);

	//set gradient 
	QLinearGradient gradientLine(0,100,200,150);
	gradientLine.setColorAt(0,Qt::red);
	gradientLine.setColorAt(0.2,Qt::black);
	gradientLine.setColorAt(0.4,Qt::yellow);
	gradientLine.setColorAt(0.6,Qt::white);
	gradientLine.setColorAt(0.8,Qt::green);
	gradientLine.setColorAt(1,Qt::blue);
	painter.setBrush(gradientLine);
	painter.drawRect(0,100,200,50);
        //set cycle gradient
        //set cycle gradient
    QRadialGradient radialGradient(300,100,100,300,100);//其中参数分别为圆形渐变的圆心( 200, 100),半径 100,和焦点( 200, 100)
    radialGradient.setColorAt(0,Qt::black);
    radialGradient.setColorAt(1,Qt::yellow); //这里让焦点和圆心重合,从而形成从圆心向外渐变的效果
    painter.setBrush(radialGradient);
    painter.drawEllipse(200,0,200,200);
}


你可能感兴趣的:(Windows,QT,VS2010)