void MyPainter::paintEvent(QPaintEvent
*/*event*/)
{
QPainter painter(this);
//设定钢笔工具
QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setWidth(1);
pen.setBrush(Qt::blue);
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
painter.setPen(pen);
//设定线性渐变工具,可加入到刷子工具中使用
QLinearGradient gradient(10,10,100,100);
gradient.setColorAt(0.0,Qt::white);
gradient.setColorAt(0.2,Qt::red);
gradient.setColorAt(0.8,Qt::black);
//设定刷子工具
QBrush brush(gradient);
//brush.setColor(Qt::red);
//brush.setStyle(Qt::SolidPattern);
painter.setBrush(brush);
//作路径
QPainterPath path;
path.moveTo(20,20);
path.cubicTo(20,45,56,39,56,45);
//设定反锯齿作图,可使得曲线平滑
painter.setRenderHint(QPainter::Antialiasing,true);
//画图
painter.save();//保存状态
//painter.drawLine(10,10,200,200);
painter.drawRect(10,10,50,50);
//painter
//painter.drawPath(path);
painter.restore();//恢复状态
}
阅读(1515) | 评论(0) | 转发(0) |