2019独角兽企业重金招聘Python工程师标准>>>
#include "widget.h"
#include "ui_widget.h"
#include
{ui->setupUi(this);
}Widget::~Widget()
{delete ui;
}void Widget::paintEvent(QPaintEvent *)
{QPainter painter(this);painter.setRenderHint(QPainter::Antialiasing);switch(this->drawShape){case Widget::Line:painter.setPen(QPen(Qt::red,20));painter.drawLine(80,100,200,100);painter.setPen(QPen(Qt::black,20,Qt::SolidLine,Qt::RoundCap));painter.drawLine(80,180,480,180);painter.setPen(QPen(Qt::blue,20,Qt::SolidLine,Qt::RoundCap));painter.drawLine(80,280,650,280);break;case Widget::Ellipse:painter.setPen(QPen(Qt::yellow,15,Qt::SolidLine,Qt::SquareCap));// painter.setPen(QPen(Qt::yellow,15,Qt::DashDotLine,Qt::RoundCap));painter.setBrush(QBrush(Qt::blue));painter.drawEllipse(200,300,150,300);break;case Widget::Pie:painter.setPen(QPen(Qt::black,15,Qt::SolidLine,Qt::RoundCap,Qt::MiterJoin));painter.setBrush(QBrush(Qt::blue,Qt::DiagCrossPattern));// painter.drawEllipse(80,80,400,240);painter.drawPie(80,80,400,240,10*10,300*16);break;}
}void Widget::on_drawLinepushButton_clicked()
{drawShape = Widget::Line;update();
}void Widget::on_EllispepushButton_clicked()
{drawShape = Widget::Ellipse;update();
}void Widget::on_PiepushButton_clicked()
{drawShape = Widget::Pie;update();
}