当前位置:网站首页>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);
边栏推荐
猜你喜欢
Markdown 中设置图片图注
微信公众号无限回调授权系统源码 全网首发
首发织梦百度推送插件全自动收录优化seo收录模块
1091: two or three things in childhood (multi instance test)
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
Idea console color log
MVVM of WPF
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
杰理之BLE【篇】
随机推荐
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
MPLS experiment
Thought map of data warehouse construction
L'auteur est mort? Ai utilise l'art pour conquérir l'humanité
chrome查看页面fps
(4) Web security | penetration testing | network security web site source code and related analysis
OpenJudge NOI 2.1 1661:Bomb Game
C - Inheritance - hidden method
TypeScript 函数定义
作者已死?AI正用藝術征服人類
杰理之BLE【篇】
杰理之BLE【篇】
Path analysis model
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
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
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
TypeScript void 基础类型
leetcode841. Keys and rooms (medium)
TypeScript 接口属性
Seriously recommend several machine learning official account