当前位置:网站首页>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,一看就觉得好,毕竟我们要画不同的物品,那用不同画刷,不是很自然吗?事实却是,不能这么干,虽说定义的这些画刷都能工作,但是,颜色值只有最后设置的一种,也就是说,这样子设置无意义。
还有一种情况,如下:
边栏推荐
- Small hair cat Internet of things platform construction and application model
- SSRS筛选器的IN运算(即包含于)用法
- Detailed explanation of Audi EDI invoice message
- c# . Net MVC uses Baidu ueditor rich text box to upload files (pictures, videos, etc.)
- What is the application technology of neural network and Internet of things
- What are the consequences of closing the read / write channel?
- 剑指 Offer II 80-100(持续更新)
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- 长城证券开户安全吗 股票开户流程网上开户
- 关于联邦学习和激励的相关概念(1)
猜你喜欢
九齐NY8B062D MCU规格书/datasheet
QT writing the Internet of things management platform 38- multiple database support
FS8B711S14电动红酒开瓶器单片机IC方案开发专用集成IC
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world
Flet教程之 05 OutlinedButton基础入门(教程含源码)
Jiuqi ny8b062d MCU specification /datasheet
Dynamic memory management
C language - Introduction - Foundation - grammar - process control (VII)
[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
随机推荐
What is involution?
Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
C # better operation mongodb database
Understand the reading, writing and creation of files in go language
关于联邦学习和激励的相关概念(1)
Optimize if code with policy mode [policy mode]
原来这才是 BGP 协议
Lingyun going to sea | Murong Technology & Huawei cloud: creating a model of financial SaaS solutions in Africa
Prometheus installation
[graduation season] green ant new fermented grains wine, red mud small stove. If it snows late, can you drink a cup?
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Process of manually encrypt the mass-producing firmware and programming ESP devices
Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
Pointnet / pointnet++ point cloud data set processing and training
Cdga | six principles that data governance has to adhere to
Flet tutorial 05 outlinedbutton basic introduction (tutorial includes source code)
repeat_ P1002 [NOIP2002 popularization group] cross the river pawn_ dp
What are the consequences of closing the read / write channel?
凌云出海记 | 一零跃动&华为云:共助非洲普惠金融服务
解密函数计算异步任务能力之「任务的状态及生命周期管理」