当前位置:网站首页>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);
边栏推荐
- input显示当前选择的图片
- Uninstall Google drive hard drive - you must exit the program to uninstall
- 力扣(LeetCode)184. 部门工资最高的员工(2022.07.03)
- Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
- left_and_right_net正常版本
- 谷歌 Chrome 浏览器将支持选取文字翻译功能
- 19. Framebuffer application programming
- Zzulioj:1201: mode problem
- Design and implementation of redis 7.0 multi part AOF
- VB.net 简单的处理图片,黑白(类库——7)
猜你喜欢

Introduction to AMBA

How to solve the component conflicts caused by scrollbars in GridView

High performance parallel programming and optimization | lesson 02 homework at home

C # character similarity comparison general class

1480. Dynamic sum of one-dimensional array

1480. 一维数组的动态和

Weekly summary (*63): about positive energy

LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout

【雕爷学编程】Arduino动手做(105)---压电陶瓷振动模块

体验碎周报第 102 期(2022.7.4)
随机推荐
The end of the Internet is rural revitalization
One click filtering to select Baidu online disk files
云原生架构实战案例及优化解决方案
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
win10清除快速访问-不留下痕迹
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
fastjson
px em rem的区别
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
复合非线性反馈控制(二)
Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs
input显示当前选择的图片
Accidentally deleted the data file of Clickhouse, can it be restored?
webrtc 快速搭建 视频通话 视频会议
Qt发布多语言国际化翻译
[microservice] Nacos cluster building and loading file configuration
[excel] PivotChart
Arc135 C (the proof is not very clear)
JS string splicing enhancement
Kubernets first meeting