绘图使用画家类QPainter
void Dialog::paintEvent(QPaintEvent *event)
{
QPainter painter(this);//在此文本框绘图
//前两个参数是坐标轴,后两个为图形参数
painter.drawLine(10,20,100,200);//划线
painter.drawRect(100,200,50,50);//矩形
painter.drawEllipse(100,200,50,50);//椭圆 画圆
painter.drawText(100,100,"55555");//输出文本信息
//画正N边形
int N=6;
QPoint* points=new QPoint[N];
for(int i=0;i<N;i++)
{
double x=200+200*cos(2*PIE/N*i);
double y=200+200*sin(2*PIE/N*i);
points[i]=QPoint(x,y);
}
painter.drawPolygon(points,N);//参数为点集,点的个数
使用QPainter在QPixmap中画图
//要包含头文件#include<QPixmap>
void Dialog::paintEvent(QPaintEvent *event)
{
QPixmap map(":/image/timg.jpg");
QRect x(0,0,6016,4016);//复制图像(0,0)开始,到(6016,4016)
QRect h(0,0,width()