当前位置:网站首页>Qt五子棋人机对战画棋子之QPainter的使用误区总结
Qt五子棋人机对战画棋子之QPainter的使用误区总结
2022-07-04 19:05:00 【新潮技术研究社】
承接上一篇五子棋画棋盘之后,我们要进行下一步的操作了,简要分解一下功能:
1.落子,我方和对方落子,这里的子功能包括:谁先手,后手如何落子问题
2.如何保留棋盘上棋子,目前我们每画一次,棋子就会消失了,所以需要保存棋盘上棋子的位置信息,那个点位需要同时画图
3.把棋子画在网格点上,需要一些计算

回到正题,无论画什么,都是在paintEvent中画的,所以,画不同的东西,就需要使用不同的标记。
我们先来看一些错误的QPainter使用案例:
QPainter blackPainter(this);
QPainter whitePainter(this);
QPainter greenPainter(this);
blackPainter.setBrush(Qt::black);
whitePainter.setBrush(Qt::white);
greenPainter.setBrush(Qt::green);如上图, 想的挺好的,分别创建多个QPainter,一看就觉得好,毕竟我们要画不同的物品,那用不同画刷,不是很自然吗?事实却是,不能这么干,虽说定义的这些画刷都能工作,但是,颜色值只有最后设置的一种,也就是说,这样子设置无意义。
还有一种情况,如下:
边栏推荐
- Optimize if code with policy mode [policy mode]
- 华为云云商店首页 Banner 资源位申请
- Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
- Flet教程之 07 PopupMenuButton基础入门(教程含源码)
- 栈:如何实现有效括号的判断?
- C # better operation mongodb database
- YOLOv5s-ShuffleNetV2
- AP8022开关电源小家电ACDC芯片离线式开关电源IC
- The problem of the maximum difference between the left and right maxima
- Small hair cat Internet of things platform construction and application model
猜你喜欢
![[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born](/img/0b/73f0d98a6db813e54074abe199ed98.png)
[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born

强化学习-学习笔记2 | 价值学习

应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设

Application practice | Shuhai supply chain construction of data center based on Apache Doris

So this is the BGP agreement

Flet tutorial 05 outlinedbutton basic introduction (tutorial includes source code)

电脑页面不能全屏怎么办?Win11页面不能全屏的解决方法

精选综述 | 用于白内障分级/分类的机器学习技术
![[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt](/img/0d/aa7f82fada743ea2ec23355ef954df.jpg)
[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt

Pointnext: review pointnet through improved model training and scaling strategies++
随机推荐
What does the neural network Internet of things mean? Popular explanation
输入的查询SQL语句,是如何执行的?
What is the application technology of neural network and Internet of things
[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born
电脑共享打印机拒绝访问要怎么办
九齐NY8B062D MCU规格书/datasheet
Flet教程之 08 AppBar工具栏基础入门(教程含源码)
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
华为nova 10系列支持应用安全检测功能 筑牢手机安全防火墙
Practice examples to understand JS strong cache negotiation cache
Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
#夏日挑战赛#带你玩转HarmonyOS多端钢琴演奏
为什么最大速度是光速
Template_ Judging prime_ Square root / six prime method
C language - Introduction - Foundation - grammar - process control (VII)
repeat_ P1002 [NOIP2002 popularization group] cross the river pawn_ dp
NetCore3.1 Json web token 中间件
Detailed explanation of Audi EDI invoice message
What ppt writing skills does the classic "pyramid principle" teach us?
凌云出海记 | 沐融科技&华为云:打造非洲金融SaaS解决方案样板