头文件包含
#include <QPainter> #include <QPen>
具体代码实现
QPainter painter(this); QPen pen; QBrush brush; //背景绘制 QPixmap pix; pix.load("C:\\Users\\23999\\Desktop\\tool-mastar\\stylle_toolV1.4\\img\\background.jpg");//背景图片位置 painter.drawPixmap(0, 0, 600, 368, pix);//位置大小以及pix配置传入,画图 //蛇的配置 pen.setColor(Qt::green); brush.setColor(Qt::darkGreen); brush.setStyle(Qt::SolidPattern); painter.setPen(pen); //送笔 painter.setBrush(brush); //送笔刷 painter.drawRect(snake[0]); for (int i = 1; i < snake.length(); i++) { painter.drawRect(snake[i]); } //食物的配置 pen.setColor(Qt::blue); brush.setColor(Qt::darkBlue); brush.setStyle(Qt::SolidPattern); painter.setPen(pen); //送笔 painter.setBrush(brush); //送笔刷 painter.drawEllipse(rewardNode[0]); //圆形