QPainter基本绘图(点、线、图形)

  QPainter绘图原理与MFC下GDI绘图原理基本一致,只是Qt平台底层应用的是Direct2D及OpenGL,而MFC下应用的GDI是windows原生的绘图渲染系统。MFC与GDI+绘图在该博客另外的分类随笔中介绍过,Qt下绘图所用的函数、方法等都与MFC下GDI绘制有相似的地方。

 1 void Widget::paintEvent(QPaintEvent *event)
 2 {
 3     Q_UNUSED(event);
 4 
 5     QPainter painter(this);
 6 
 7     painter.fillRect(this->rect(),QBrush(QColor(0,0,0)));
 8     painter.setRenderHint(QPainter::Antialiasing);//抗锯齿
 9     painter.setPen(QPen(QColor(255,0,0)));
10 
11     painter.drawPoint(10,10);
12     painter.drawLine(11,11,this->rect().width()/2,this->rect().height()/2);
13     painter.drawEllipse(this->rect().width()/2,this->rect().height()/2,50,50);
14     painter.drawArc(this->rect().width()/2+50,this->rect().height()/2+50,50,50,0,90*16);
15 }

image

posted @ 2026-01-21 11:09  左边的翼  阅读(3)  评论(0)    收藏  举报