当前位置:网站首页>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);
边栏推荐
- Solar insect killing system based on single chip microcomputer
- el-select如何实现懒加载(带搜索功能)
- Recommended system 1 --- framework
- 每周小结(*63):关于正能量
- 报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
- What are the reasons for the frequent high CPU of ECS?
- Viewing and using binary log of MySQL
- Grounding relay dd-1/60
- SQL performance optimization skills
- 注释与注解
猜你喜欢
谷歌 Chrome 浏览器将支持选取文字翻译功能
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
ANSYS command
Introduction to AMBA
Uninstall Google drive hard drive - you must exit the program to uninstall
BUU-Reverse-easyre
gslb(global server load balance)技术的一点理解
Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
接地继电器DD-1/60
Leakage detection relay jy82-2p
随机推荐
Recommended system 1 --- framework
webrtc 快速搭建 视频通话 视频会议
XII Golang others
Zzulioj:1201: mode problem
如何获取el-tree中所有节点的父节点
Principle and practice of common defects in RSA encryption application
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
Descriptive analysis of data distribution characteristics (data exploration)
px em rem的区别
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
BUU-Crypto-Cipher
Leetcode question brushing record | 206_ Reverse linked list
配置交叉编译工具链和环境变量
left_ and_ right_ Net normal version
JS get the attribute values nested in the object
[excel] PivotChart
JS arguments parameter usage and explanation
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
【雕爷学编程】Arduino动手做(105)---压电陶瓷振动模块
总线的基本概念