当前位置:网站首页>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,一看就觉得好,毕竟我们要画不同的物品,那用不同画刷,不是很自然吗?事实却是,不能这么干,虽说定义的这些画刷都能工作,但是,颜色值只有最后设置的一种,也就是说,这样子设置无意义。
还有一种情况,如下:
边栏推荐
- Win11无法将值写入注册表项如何解决?
- 华为nova 10系列支持应用安全检测功能 筑牢手机安全防火墙
- [ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
- 凌云出海记 | 一零跃动&华为云:共助非洲普惠金融服务
- 软件客户端数字签名一定要申请代码签名证书吗?
- 输入的查询SQL语句,是如何执行的?
- AP8022开关电源小家电ACDC芯片离线式开关电源IC
- What ppt writing skills does the classic "pyramid principle" teach us?
- Practical examples of node strong cache and negotiation cache
- 应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
猜你喜欢
In operation (i.e. included in) usage of SSRs filter
Form组件常用校验规则-1(持续更新中~)
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world
New wizard effect used by BCG
Practice examples to understand JS strong cache negotiation cache
Win11无法将值写入注册表项如何解决?
Application practice | Shuhai supply chain construction of data center based on Apache Doris
What is involution?
Wireshark network packet capture
随机推荐
Regular replacement [JS, regular expression]
go语言笔记(4)go常用管理命令
HMM hidden Markov model and code implementation
Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
Cdga | six principles that data governance has to adhere to
Small hair cat Internet of things platform construction and application model
Why is the maximum speed the speed of light
输入的查询SQL语句,是如何执行的?
【历史上的今天】7 月 4 日:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生
Win11怎么搜索无线显示器?Win11查找无线显示器设备的方法
Informatics Olympiad 1336: [example 3-1] find roots and children
紫光展锐完成全球首个 5G R17 IoT NTN 卫星物联网上星实测
Offset function and windowing function
九齐NY8B062D MCU规格书/datasheet
Optimize if code with policy mode [policy mode]
Template_ Large integer subtraction_ Regardless of size
Template_ Judging prime_ Square root / six prime method
Aiming at the "amnesia" of deep learning, scientists proposed that based on similarity weighted interleaved learning, they can board PNAS
九齐单片机NY8B062D单按键控制4种LED状态
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines