当前位置:网站首页>QT 获取随机颜色值设置label背景色 代码
QT 获取随机颜色值设置label背景色 代码
2022-07-04 05:49:00 【程序媛zcc】
需求创建 widget 时,设置随机背景色,如图。
主要代码:
#include <iostream>
#include <random>
using namespace std;
std::default_random_engine e;
std::uniform_real_distribution<double> random(0,1);
// 获取随机颜色
QColor color = QColor::fromRgb(int(random(e)*255), int(random(e)*255), int(random(e)*255));
QString winColor = color.name();
//设置背景色方法一
ui->signColor->setStyleSheet("QLabel{background-color: "+ winColor + ";border:2px groove #191919;}");
//方法二
ui->signColor->setStyleSheet("background-color:rgb("+ QString::number(int(random(e)*255)) + "," +
QString::number(int(random(e)*255)) + "," + QString::number(int(random(e)*255)) + ");");
//获取 r/g/b 值
QColor color = QColorDialog::getColor(Qt::white, this);
qDebug() << "颜色选择" << color << color.name();
QRgb rgb = color.rgb();
qDebug() << "rgb== " << qRed(rgb) << qGreen(rgb) << qBlue(rgb);
边栏推荐
- 接地继电器DD-1/60
- Use of hutool Pinyin tool
- Nexus 6p从8.0降级6.0+root
- Install pytoch geometric
- Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
- 注释与注解
- JS how to convert seconds into hours, minutes and seconds display
- What is MQ?
- Actual cases and optimization solutions of cloud native architecture
- 每周小结(*63):关于正能量
猜你喜欢
VB. Net simple processing pictures, black and white (class library - 7)
BUU-Reverse-easyre
1480. Dynamic sum of one-dimensional array
如何展开Collapse 的所有折叠面板
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
每周小结(*63):关于正能量
Upper computer software development - log information is stored in the database based on log4net
AWT常用组件、FileDialog文件选择框
High performance parallel programming and optimization | lesson 02 homework at home
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
随机推荐
Tutle clock improved version
BUU-Crypto-[GUET-CTF2019]BabyRSA
AWT介绍
1480. 一维数组的动态和
[excel] PivotChart
Void convolution, deformable convolution, deformable ROI pooling
Canoe panel learning video
Leakage detection relay jy82-2p
JS flattened array of number shape structure
How much computing power does transformer have
Steady! Huawei micro certification Huawei cloud computing service practice is stable!
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
left_ and_ right_ Net normal version
Detectron:训练自己的数据集——将自己的数据格式转换成COCO格式
Take you to quickly learn how to use qsort and simulate qsort
Experience weekly report no. 102 (July 4, 2022)
Upper computer software development - log information is stored in the database based on log4net
Introduction to AMBA
Weekly summary (*63): about positive energy
BUU-Crypto-Cipher