当前位置:网站首页>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,一看就觉得好,毕竟我们要画不同的物品,那用不同画刷,不是很自然吗?事实却是,不能这么干,虽说定义的这些画刷都能工作,但是,颜色值只有最后设置的一种,也就是说,这样子设置无意义。
还有一种情况,如下:
边栏推荐
- NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
- 原来这才是 BGP 协议
- Common verification rules of form components -1 (continuously updating ~)
- Selected review | machine learning technology for Cataract Classification / classification
- How is the entered query SQL statement executed?
- Application practice | Shuhai supply chain construction of data center based on Apache Doris
- Taishan Office Technology Lecture: about the order of background (shading and highlighting)
- Practical examples of node strong cache and negotiation cache
- C # better operation mongodb database
- 更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
猜你喜欢

Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
node强缓存和协商缓存实战示例

The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!

What is the application technology of neural network and Internet of things
![Regular replacement [JS, regular expression]](/img/66/abfe0bd6050b7266ad269d655be644.png)
Regular replacement [JS, regular expression]

托管式服务网络:云原生时代的应用体系架构进化

太方便了,钉钉上就可完成代码发布审批啦!

复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算

Employment prospects and current situation of Internet of things application technology

应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
随机推荐
Flet教程之 06 TextButton基础入门(教程含源码)
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
Why is the maximum speed the speed of light
In operation (i.e. included in) usage of SSRs filter
Huawei Nova 10 series supports the application security detection function to build a strong mobile security firewall
Taishan Office Technology Lecture: about the order of background (shading and highlighting)
NetCore3.1 Json web token 中间件
Informatics Olympiad 1336: [example 3-1] find roots and children
什么是区块哈希竞猜游戏系统开发?哈希竞猜游戏系统开发(案例成熟)
Oracle database, numbers Force 2 decimal places to display-Alibaba Cloud
同事的接口文档我每次看着就头大,毛病多多。。。
Win11怎么搜索无线显示器?Win11查找无线显示器设备的方法
HMM hidden Markov model and code implementation
强化学习-学习笔记2 | 价值学习
长城证券开户安全吗 股票开户流程网上开户
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
YOLOv5s-ShuffleNetV2
被奉为经典的「金字塔原理」,教给我们哪些PPT写作技巧?
应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
剑指 Offer II 80-100(持续更新)