当前位置:网站首页>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,一看就觉得好,毕竟我们要画不同的物品,那用不同画刷,不是很自然吗?事实却是,不能这么干,虽说定义的这些画刷都能工作,但是,颜色值只有最后设置的一种,也就是说,这样子设置无意义。
还有一种情况,如下:
边栏推荐
- Dark horse programmer - software testing - stage 07 2-linux and database -09-24-linux command learning steps, wildcards, absolute paths, relative paths, common commands for files and directories, file
- NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
- Process of manually encrypt the mass-producing firmware and programming ESP devices
- On communication bus arbitration mechanism and network flow control from the perspective of real-time application
- What is the application technology of neural network and Internet of things
- Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
- Cbcgptabwnd control used by BCG (equivalent to MFC TabControl)
- 【ISMB2022教程】图表示学习的精准医疗,哈佛大学Marinka Zitnik主讲,附87页ppt
- In operation (i.e. included in) usage of SSRs filter
- go语言笔记(4)go常用管理命令
猜你喜欢

上线首月,这家露营地游客好评率高达99.9%!他是怎么做到的?

So this is the BGP agreement
![NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]](/img/79/82763392e74d102921b4e8e601d4c6.png)
NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]

NetCore3.1 Json web token 中间件

紫光展锐完成全球首个 5G R17 IoT NTN 卫星物联网上星实测
Understand the reading, writing and creation of files in go language

Win11亮度被锁定怎么办?Win11亮度被锁定的解决方法

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

什么叫内卷?

FS8B711S14电动红酒开瓶器单片机IC方案开发专用集成IC
随机推荐
Optimize if code with policy mode [policy mode]
Win11亮度被锁定怎么办?Win11亮度被锁定的解决方法
Anhui Zhong'an online culture and tourism channel launched a series of financial media products of "follow the small editor to visit Anhui"
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
LeetCode 871. 最低加油次数
上线首月,这家露营地游客好评率高达99.9%!他是怎么做到的?
Is it necessary to apply for code signing certificate for software client digital signature?
Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
Detailed explanation of Audi EDI invoice message
SSRS筛选器的IN运算(即包含于)用法
华为云云商店首页 Banner 资源位申请
电脑共享打印机拒绝访问要怎么办
Hash quiz game system development how to develop hash quiz game system development (multiple cases)
Pointnext: review pointnet through improved model training and scaling strategies++
Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
What is involution?
Aiming at the "amnesia" of deep learning, scientists proposed that based on similarity weighted interleaved learning, they can board PNAS
Why is the maximum speed the speed of light
针对深度学习的“失忆症”,科学家提出基于相似性加权交错学习,登上PNAS
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise