当前位置:网站首页>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);
边栏推荐
- #systemverilog# 可綜合模型的結構總結
- [MySQL learning notes 30] lock (non tutorial)
- Uni app practical project
- Set picture annotation in markdown
- Ble of Jerry [chapter]
- 升级版手机检测微信工具小程序源码-支持多种流量主模式
- TypeScript 可索引类型
- Path analysis model
- How are the open source Netease cloud music API projects implemented?
- If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
猜你喜欢

升级版手机检测微信工具小程序源码-支持多种流量主模式

Week6 weekly report

Leetcode59. spiral matrix II (medium)

word中如何删除某符号前面或后面所有的文字

How MySQL merges data

Idea console color log
![[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code](/img/93/ec9de907cae4714038bb5f95aba52b.png)
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code

CDN acceleration and cracking anti-theft chain function

变量的命名规则十二条

Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
随机推荐
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
Jerry's general penetration test - do data transmission with app Communication [article]
Word delete the contents in brackets
[JDBC] quick start tutorial
Configure raspberry pie access network
The differences and advantages and disadvantages between cookies, seeion and token
Select all the lines with a symbol in word and change them to titles
剪映的相关介绍
The way to learn go (I) the basic introduction of go to the first HelloWorld
[MySQL learning notes 30] lock (non tutorial)
leetcode704. Binary search (find an element, simple, different writing)
How to configure GUI guide development environment
Fundamentals of C language 9: Functions
Word setting directory
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
GET/POST/PUT/PATCH/DELETE含义
Typescript interface properties
1189. Maximum number of "balloons"
Cookie技术&Session技术&ServletContext对象
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]