当前位置:网站首页>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);
边栏推荐
- Upper computer software development - log information is stored in the database based on log4net
- Qt发布多语言国际化翻译
- Take you to quickly learn how to use qsort and simulate qsort
- AWT常用组件、FileDialog文件选择框
- 2022.7.2-----leetcode.871
- AWT介绍
- left_ and_ right_ Net interpretable design
- Gridview出现滚动条,组件冲突,如何解决
- Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
- The end of the Internet is rural revitalization
猜你喜欢
Component、Container容器常用API详解:Frame、Panel、ScrollPane
如何避免 JVM 内存泄漏?
卸载Google Drive 硬盘-必须退出程序才能卸载
Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
1480. Dynamic sum of one-dimensional array
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
Gridview出现滚动条,组件冲突,如何解决
Grounding relay dd-1/60
C语言练习题(递归)
[openvino+paddle] paddle detection / OCR / SEG export based on paddle2onnx
随机推荐
复合非线性反馈控制(二)
Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
How does apscheduler set tasks not to be concurrent (that is, execute the next task after the first one)?
一键过滤选择百度网盘文件
(4) Canal multi instance use
VB. Net simple processing pictures, black and white (class library - 7)
FRP intranet penetration, reverse proxy
1.1 history of Statistics
AWT common components, FileDialog file selection box
安装 Pytorch geometric
The difference between PX EM rem
Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
Online shrimp music will be closed in January next year. Netizens call No
BUU-Crypto-Cipher
2022.7.3-----leetcode.556
Kubernets first meeting
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
(4) Canal multi instance use
MySQL information_ Schema database
Grounding relay dd-1/60