当前位置:网站首页>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);
边栏推荐
- 升级版手机检测微信工具小程序源码-支持多种流量主模式
- Redis builds clusters
- 杰理之BLE【篇】
- js对象获取属性的方法(.和[]方式)
- 杰理之BLE【篇】
- OpenJudge NOI 2.1 1749:数字方格
- Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
- Internal and external troubles of "boring ape" bayc
- 巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
- 杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
猜你喜欢
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
SSM learning
升级版手机检测微信工具小程序源码-支持多种流量主模式
Set picture annotation in markdown
jmeter性能测试步骤实战教程
作者已死?AI正用藝術征服人類
Oracle column to row -- a field is converted to multiple rows according to the specified separator
The best way to learn SEO: search engine
Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
Twelve rules for naming variables
随机推荐
MPLS experiment
剪映的相关介绍
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
Ble of Jerry [chapter]
Jerry's ad series MIDI function description [chapter]
After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions
The best way to learn SEO: search engine
GET/POST/PUT/PATCH/DELETE含义
Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
杰理之AD 系列 MIDI 功能说明【篇】
CDN acceleration and cracking anti-theft chain function
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
navicat如何导入MySQL脚本
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
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
C语言 简单易懂的高精度加法
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution