当前位置:网站首页>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);
边栏推荐
猜你喜欢
SSM learning
呆错图床系统源码图片CDN加速与破解防盗链功能
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
Go learning --- use reflection to judge whether the value is valid
Ble of Jerry [chapter]
OpenGL ES 学习初识(1)
杰理之BLE【篇】
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
SSM学习
Jerry's ad series MIDI function description [chapter]
随机推荐
Introduction to the basics of network security
JDBC learning notes
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
杰理之BLE【篇】
数字IC设计笔试题汇总(一)
TypeScript 变量作用域
网络安全基础介绍
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
杰理之AD 系列 MIDI 功能说明【篇】
CDN acceleration and cracking anti-theft chain function
Jerry needs to modify the profile definition of GATT [chapter]
多线程和并发编程(二)
Fundamentals of C language 9: Functions
mysql如何合并数据
navicat如何导入MySQL脚本
supervisor 使用文档
How can word delete English only and keep Chinese or delete Chinese and keep English
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程