当前位置:网站首页>Summary of the mistakes in the use of qpainter in QT gobang man-machine game

Summary of the mistakes in the use of qpainter in QT gobang man-machine game

2022-07-04 20:43:00 Trendy technology research society

After the last Gobang drawing board , We are going to proceed to the next step , Briefly break down the functions :

1. Move later , Our side and the other side fall , The sub functions here include : Who's first , How to settle the problem of backhand

2. How to keep the pieces on the chessboard , At present, every time we draw , The chess pieces will disappear , So you need to save the position information of the pieces on the chessboard , That point needs to be drawn at the same time

3. Draw the chess pieces on the grid , Need some calculation

  Back to the point , Whatever you draw , It's all in paintEvent It's in Chinese , therefore , Draw different things , You need to use different tags .

Let's first look at some wrong QPainter Use cases :

QPainter blackPainter(this);
	QPainter whitePainter(this);
	QPainter greenPainter(this);
	blackPainter.setBrush(Qt::black);
	whitePainter.setBrush(Qt::white);
	greenPainter.setBrush(Qt::green);

Pictured above , Think very well , Create multiple QPainter, I feel good at first sight , After all, we have to draw different objects , Then use different brushes , Isn't it natural ? The truth is , You can't do that , Although these brushes defined can work , however , There is only one color value set last , in other words , This setting is meaningless .

There's another situation , as follows :

原网站

版权声明
本文为[Trendy technology research society]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041905258009.html