当前位置:网站首页>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);
边栏推荐
- Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs
- HMS v1.0 appointment. PHP editid parameter SQL injection vulnerability (cve-2022-25491)
- Invalid revision: 3.18.1-g262b901-dirty
- Wechat applet +php realizes authorized login
- "In simple language programming competition (basic)" part 1 Introduction to language Chapter 3 branch structure programming
- Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
- LC weekly 300
- JS flattened array of number shape structure
- JS get the attribute values nested in the object
- Detailed explanation of common APIs for component and container containers: frame, panel, scrollpane
猜你喜欢
Canoe panel learning video
[excel] PivotChart
云原生架构实战案例及优化解决方案
How much computing power does transformer have
Win10 clear quick access - leave no trace
【微服务】Nacos集群搭建以及加载文件配置
win10清除快速访问-不留下痕迹
JS how to convert seconds into hours, minutes and seconds display
LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
How to get the parent node of all nodes in El tree
随机推荐
JS arguments parameter usage and explanation
AWT常用组件、FileDialog文件选择框
Introduction To AMBA 简单理解
Invalid revision: 3.18.1-g262b901-dirty
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
Take you to quickly learn how to use qsort and simulate qsort
HMS v1.0 appointment. PHP editid parameter SQL injection vulnerability (cve-2022-25491)
buuctf-pwn write-ups (8)
VB. Net calls ffmpeg to simply process video (class Library-6)
Nexus 6p从8.0降级6.0+root
What is MQ?
ANSYS command
gslb(global server load balance)技术的一点理解
注释与注解
lightroom 导入图片灰色/黑色矩形 多显示器
Design and implementation of tcp/ip series overview
A little understanding of GSLB (global server load balance) technology
Experience weekly report no. 102 (July 4, 2022)
Sword finger offer II 038 Daily temperature
XII Golang others