当前位置:网站首页>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);
边栏推荐
- Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
- Input displays the currently selected picture
- How to implement lazy loading in El select (with search function)
- Accidentally deleted the data file of Clickhouse, can it be restored?
- BUU-Crypto-[GUET-CTF2019]BabyRSA
- Understanding of cross domain and how to solve cross domain problems
- 70000 words of detailed explanation of the whole process of pad openvino [CPU] - from environment configuration to model deployment
- Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
- Penetration tool - sqlmap
- 体验碎周报第 102 期(2022.7.4)
猜你喜欢
Configure cross compilation tool chain and environment variables
Leakage detection relay jy82-2p
How to solve the component conflicts caused by scrollbars in GridView
Google Chrome browser will support the function of selecting text translation
JS execution mechanism
How to expand all collapse panels
QT QTableWidget 表格列置顶需求的思路和代码
BUU-Crypto-[GXYCTF2019]CheckIn
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
【微服务】Nacos集群搭建以及加载文件配置
随机推荐
input显示当前选择的图片
Introduction To AMBA 简单理解
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
Qt发布多语言国际化翻译
How to configure static IP for Kali virtual machine
BUU-Crypto-[GXYCTF2019]CheckIn
FRP intranet penetration, reverse proxy
Online shrimp music will be closed in January next year. Netizens call No
The end of the Internet is rural revitalization
QT releases multilingual International Translation
el-select如何实现懒加载(带搜索功能)
win10清除快速访问-不留下痕迹
Leakage detection relay jy82-2p
Penetration tool - sqlmap
Take you to quickly learn how to use qsort and simulate qsort
Experience weekly report no. 102 (July 4, 2022)
How to determine whether an array contains an element
(4) Canal multi instance use
Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
AWT common components, FileDialog file selection box