当前位置:网站首页>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);
边栏推荐
- VB.net 简单的处理图片,黑白(类库——7)
- Install pytoch geometric
- How to clone objects
- Kubernets first meeting
- 724. Find the central subscript of the array
- Introduction To AMBA 简单理解
- Penetration tool - sqlmap
- 509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
- The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
- LC weekly 300
猜你喜欢

Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs

Google Chrome browser will support the function of selecting text translation

Kubernets first meeting

SQL injection - injection based on MSSQL (SQL Server)

体验碎周报第 102 期(2022.7.4)

Void convolution, deformable convolution, deformable ROI pooling

Solar insect killing system based on single chip microcomputer

Simulink and Arduino serial port communication

Canoe panel learning video

AWT介绍
随机推荐
如何获取el-tree中所有节点的父节点
Compound nonlinear feedback control (2)
【微服务】Nacos集群搭建以及加载文件配置
How much computing power does transformer have
One click filtering to select Baidu online disk files
win10清除快速访问-不留下痕迹
BUU-Real-[PHP]XXE
[microservice] Nacos cluster building and loading file configuration
724. 寻找数组的中心下标
Leakage detection relay jy82-2p
我的NVIDIA开发者之旅——优化显卡性能
Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
[Chongqing Guangdong education] electronic circuit homework question bank of RTVU secondary school
Notepad++ -- display related configurations
Component、Container容器常用API详解:Frame、Panel、ScrollPane
What are the reasons for the frequent high CPU of ECS?
How to solve the component conflicts caused by scrollbars in GridView
Wechat applet +php realizes authorized login
Accidentally deleted the data file of Clickhouse, can it be restored?
left_and_right_net正常版本