当前位置:网站首页>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);
边栏推荐
- Detectron:训练自己的数据集——将自己的数据格式转换成COCO格式
- How to use postman to realize simple interface Association [add, delete, modify and query]
- 云原生架构实战案例及优化解决方案
- HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
- BUU-Reverse-easyre
- Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first
- Canoe panel learning video
- Zzulioj:1201: mode problem
- el-select如何实现懒加载(带搜索功能)
- How to solve the component conflicts caused by scrollbars in GridView
猜你喜欢
[microservice] Nacos cluster building and loading file configuration
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
My NVIDIA developer journey - optimizing graphics card performance
JS how to convert seconds into hours, minutes and seconds display
724. Find the central subscript of the array
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
Leakage detection relay jy82-2p
Supplement the JS of a video website to decrypt the video
Input displays the currently selected picture
How to configure static IP for Kali virtual machine
随机推荐
BUU-Crypto-[GXYCTF2019]CheckIn
Uninstall Google drive hard drive - you must exit the program to uninstall
Letter meaning and parameter abbreviation of optical module Daquan
How to get the parent node of all nodes in El tree
【微服务】Nacos集群搭建以及加载文件配置
VB.net GIF(制作、拆解——优化代码,类库——5)
十二. golang其他
Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
LC周赛300
Thinkphp6.0 middleware with limited access frequency think throttle
Simulink and Arduino serial port communication
input显示当前选择的图片
Easy change
Leetcode question brushing record | 206_ Reverse linked list
Recommended system 1 --- framework
Google Chrome browser will support the function of selecting text translation
ANSYS command
我的NVIDIA开发者之旅——优化显卡性能