当前位置:网站首页>QT get random color value and set label background color code
QT get random color value and set label background color code
2022-07-04 05:56:00 【Program yuan ZCC】
Requirements creation widget when , Set random background color , Pictured .
Main code :
#include <iostream>
#include <random>
using namespace std;
std::default_random_engine e;
std::uniform_real_distribution<double> random(0,1);
// Get random colors
QColor color = QColor::fromRgb(int(random(e)*255), int(random(e)*255), int(random(e)*255));
QString winColor = color.name();
// Method 1 of setting background color
ui->signColor->setStyleSheet("QLabel{background-color: "+ winColor + ";border:2px groove #191919;}");
// Method 2
ui->signColor->setStyleSheet("background-color:rgb("+ QString::number(int(random(e)*255)) + "," +
QString::number(int(random(e)*255)) + "," + QString::number(int(random(e)*255)) + ");");
// obtain r/g/b value
QColor color = QColorDialog::getColor(Qt::white, this);
qDebug() << " Color choices " << color << color.name();
QRgb rgb = color.rgb();
qDebug() << "rgb== " << qRed(rgb) << qGreen(rgb) << qBlue(rgb);
边栏推荐
- Kubernets first meeting
- 每周小结(*63):关于正能量
- left_ and_ right_ Net interpretable design
- Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
- left_and_right_net可解释性设计
- (4) Canal multi instance use
- Qt发布多语言国际化翻译
- Design and implementation of tcp/ip series overview
- AWT introduction
- How to solve the component conflicts caused by scrollbars in GridView
猜你喜欢
js arguments参数使用和详解
724. Find the central subscript of the array
Sword finger offer II 038 Daily temperature
每周小结(*63):关于正能量
Detectron: train your own data set -- convert your own data format to coco format
Win10 clear quick access - leave no trace
云原生架构实战案例及优化解决方案
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
BUU-Crypto-[HDCTF2019]basic rsa
VB. Net simple processing pictures, black and white (class library - 7)
随机推荐
19. Framebuffer application programming
Nexus 6p downgraded from 8.0 to 6.0+root
Descriptive analysis of data distribution characteristics (data exploration)
A little understanding of GSLB (global server load balance) technology
How to clone objects
MySQL的information_schema数据库
gslb(global server load balance)技术的一点理解
input显示当前选择的图片
Leetcode question brushing record | 206_ Reverse linked list
webrtc 快速搭建 视频通话 视频会议
(4) Canal multi instance use
lightroom 导入图片灰色/黑色矩形 多显示器
AWT common components, FileDialog file selection box
buuctf-pwn write-ups (8)
Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
How to expand all collapse panels
如何获取el-tree中所有节点的父节点
Detectron:训练自己的数据集——将自己的数据格式转换成COCO格式
Accidentally deleted the data file of Clickhouse, can it be restored?
"In simple language programming competition (basic)" part 1 Introduction to language Chapter 3 branch structure programming