当前位置:网站首页>QT color is converted to string and uint
QT color is converted to string and uint
2022-07-06 07:22:00 【Big and strong】
Software development , Many settings need to be used json Or other configuration files save color values , Split the color into red 、 green 、 blue 、 Four fields of transparency are too troublesome .
Here's how to save colors using a field , Is to save the color as a string or uint type , Then parse the string into color .
So let's analyze this , In many json The colors in the file are represented by the following characters :
#fffa3337
Or, ,( The above shows transparency , There is no )
#fa3337
Read into program , It can be a string , It can also be a period hex Formal uint value .
stay qt in QRgb The essence is unsigned int type , qt Source code :
Color to string
Demonstration code
// Turn the color to QRgb type ,color by QColor type
QRgb mRgb = qRgba(color.red(), color.green(), color.blue(), color.alpha());
// take QRgb Object to Hex character string
obj["Color"] = QString::number(mRgb, 16);
The output style is as follows :
"Color": "fffa3337",
String to color
Demonstration code
QString colorStr = obj["Color"].toString(); // Get color string
quint64 colorInt = colorStr.toUInt(NULL,16);
lineTemple.color = QColor(colorInt);
lineTemple.color.setAlpha(colorInt>>24);
边栏推荐
- After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions
- Typescript void base type
- 首发织梦百度推送插件全自动收录优化seo收录模块
- TS基础篇
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Structure summary of SystemVerilog integrable model
- Supervisor usage document
- LeetCode Algorithm 2181. Merge nodes between zero
- Babbitt | metauniverse daily must read: the group image of Chinese Internet enterprises pouring into metauniverse: "there are only various survival desires, and there is no ambition for forward-lookin
- qt颜色与字符串、uint相互转换
猜你喜欢
树莓派串口登录与SSH登录方法
Bugku CTF daily question: do you want seeds? Blackmailed
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
【mysql学习笔记30】锁(非教程)
Jerry's ad series MIDI function description [chapter]
Establishment and operation of cloud platform open source project environment
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
Seriously recommend several machine learning official account
剪映的相关介绍
Raspberry pie 3B update VIM
随机推荐
How to configure GUI guide development environment
SSM学习
MPLS experiment
idea控制台彩色日志
CDN acceleration and cracking anti-theft chain function
word删除括号里内容
You deserve this high-value open-source third-party Netease cloud music player
leetcode841. 钥匙和房间(中等)
(4) Web security | penetration testing | network security web site source code and related analysis
杰理之普通透传测试---做数传搭配 APP 通信【篇】
Leetcode59. spiral matrix II (medium)
#systemverilog# 可综合模型的结构总结
leetcode1020. Number of enclaves (medium)
Crawling exercise: Notice of crawling Henan Agricultural University
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
【JDBC】快速入门教程
Uni app practical project
First knowledge of OpenGL es learning (1)
Idea console color log