当前位置:网站首页>QPalette palette, frame color fill
QPalette palette, frame color fill
2022-08-01 17:38:00 【little engineer】
QPalette调色板
QFrame Box fill color
参考书籍:
Book_LuWenZhou
参考代码:
penColorLabel =new QLabel(tr("画笔颜色:")); //画笔颜色选择控件
penColorFrame =new QFrame; //形状、框架. Fill with the selected brush color
penColorFrame->setFrameStyle(QFrame::Panel|QFrame::Sunken);
penColorFrame->setAutoFillBackground(true);
penColorFrame->setPalette(QPalette(Qt::blue)); //画刷
penColorBtn =new QPushButton(tr("更改"));
connect(penColorBtn,SIGNAL(clicked()),this,SLOT(ShowPenColor()));
void MainWidget::ShowPenColor()
{
//static_cast < type-id > ( expression ) 该运算符把expression转换为type-id类型
// QColor color = QColorDialog::getColor(static_cast<int>(Qt::blue));
QColor color = QColorDialog::getColor((Qt::blue));
penColorFrame->setPalette(QPalette(color)); //设置FrameThe box is the selected color
//Update brush
int value = penWidthSpinBox->value();
Qt::PenStyle style = Qt::PenStyle(penStyleComboBox->itemData(
penStyleComboBox->currentIndex(),Qt::UserRole).toInt());
Qt::PenCapStyle cap = Qt::PenCapStyle(penCapComboBox->itemData(
penCapComboBox->currentIndex(),Qt::UserRole).toInt());
Qt::PenJoinStyle join=Qt::PenJoinStyle(penJoinComboBox->itemData(penJoinComboBox->currentIndex(),Qt::UserRole).toInt());
paintArea->setPen(QPen(color,value,style,cap,join));
}
QToolButtonTool button fill color

参考代码:
colorBtn =new QToolButton; //创建颜色选择控件
QPixmap pixmap(20,20);
pixmap.fill(Qt::black);
colorBtn->setIcon(QIcon(pixmap));
connect(colorBtn,SIGNAL(clicked()),this,SLOT(ShowColor()));
void MainWindow::ShowColor()
{
QColor color = QColorDialog::getColor(static_cast<int> (Qt::black), this);
//Use the standard color dialogQColorDialog获得一个颜色值
if(color.isValid()) //Color is selected
{
//将新选择的颜色传给绘制区,用于改变画笔的颜色值
drawWidget->setColor(color);
QPixmap p(20,20);
p.fill(color);
colorBtn->setIcon(QIcon(p)); //更新颜色选择按钮上的颜色显示
}
}
QComboBoxDrop-down option box fill color

参考代码:
#include "palette.h"
#include <QHBoxLayout>
#include <QGridLayout>
Palette::Palette(QWidget *parent)
: QDialog(parent)
{
createCtrlFrame();
createContentFrame();
QHBoxLayout *mainLayout =new QHBoxLayout(this);
mainLayout->addWidget(ctrlFrame);
mainLayout->addWidget(contentFrame);
}
void Palette::createCtrlFrame()
{
windowLabel =new QLabel(tr("QPalette::Window: ")); //背景色
windowComboBox =new QComboBox; //创建一个QComboBox对象
fillColorList(windowComboBox); //(a) Insert various color options into the drop-down list box
connect(windowComboBox,SIGNAL(activated(int)),this,SLOT(ShowWindow()));//(b)
windowTextLabel =new QLabel(tr("QPalette::WindowText: ")); //前景色(字体颜色)
windowTextComboBox =new QComboBox;
fillColorList(windowTextComboBox);
connect(windowTextComboBox,SIGNAL(activated(int)),this,SLOT(ShowWindowText()));
buttonLabel =new QLabel(tr("QPalette::Button: "));
buttonComboBox =new QComboBox;
fillColorList(buttonComboBox);
connect(buttonComboBox,SIGNAL(activated(int)),this,SLOT(ShowButton()));
buttonTextLabel =new QLabel(tr("QPalette::ButtonText: "));
buttonTextComboBox =new QComboBox;
fillColorList(buttonTextComboBox);
connect(buttonTextComboBox,SIGNAL(activated(int)),this,SLOT(ShowButtonText()));
baseLabel =new QLabel(tr("QPalette::Base: "));
baseComboBox =new QComboBox;
fillColorList(baseComboBox);
connect(baseComboBox,SIGNAL(activated(int)),this,SLOT(ShowBase()));
ctrlFrame =new QFrame; //Color selection panel
QGridLayout *mainLayout=new QGridLayout(ctrlFrame);
mainLayout->setSpacing(20);
mainLayout->addWidget(windowLabel,0,0);
mainLayout->addWidget(windowComboBox,0,1);
mainLayout->addWidget(windowTextLabel,1,0);
mainLayout->addWidget(windowTextComboBox,1,1);
mainLayout->addWidget(buttonLabel,2,0);
mainLayout->addWidget(buttonComboBox,2,1);
mainLayout->addWidget(buttonTextLabel,3,0);
mainLayout->addWidget(buttonTextComboBox,3,1);
mainLayout->addWidget(baseLabel,4,0);
mainLayout->addWidget(baseComboBox,4,1);
}
void Palette::createContentFrame()
{
label1 =new QLabel(tr("Please select a value:"));
comboBox1 =new QComboBox;
label2 =new QLabel(tr("请输入字符串:"));
lineEdit2 =new QLineEdit;
textEdit =new QTextEdit;
QGridLayout *TopLayout =new QGridLayout;
TopLayout->addWidget(label1,0,0);
TopLayout->addWidget(comboBox1,0,1);
TopLayout->addWidget(label2,1,0);
TopLayout->addWidget(lineEdit2,1,1);
TopLayout->addWidget(textEdit,2,0,1,2); //控件对象,行,列,The number of rows occupied,The number of columns occupied,对齐方式(默认为0)
OkBtn =new QPushButton(tr("确认"));
CancelBtn =new QPushButton(tr("取消"));
QHBoxLayout *BottomLayout =new QHBoxLayout;
BottomLayout->addStretch(1);
BottomLayout->addWidget(OkBtn);
BottomLayout->addWidget(CancelBtn);
contentFrame =new QFrame; // 设置显示面板
QVBoxLayout *mainLayout =new QVBoxLayout(contentFrame); // 垂直布局
mainLayout->addLayout(TopLayout); //Add sub-layout
mainLayout->addLayout(BottomLayout);
}
void Palette::ShowWindow()
{
//Get the currently selected color value
QStringList colorList = QColor::colorNames();
QColor color = QColor(colorList[windowComboBox->currentIndex()]);
QPalette p = contentFrame->palette(); //(a)
p.setColor(QPalette::Window,color); //(b) 设置窗体的windowClass color theme,颜色值为color
//Apply the modified palette information to contentFrame窗体中,更新显示
contentFrame->setPalette(p);
contentFrame->update();
}
void Palette::ShowWindowText()
{
QStringList colorList = QColor::colorNames();
QColor color = colorList[windowTextComboBox->currentIndex()];
QPalette p = contentFrame->palette();
p.setColor(QPalette::WindowText,color);
contentFrame->setPalette(p);
}
void Palette::ShowButton()
{
QStringList colorList = QColor::colorNames();
QColor color =QColor(colorList[buttonComboBox->currentIndex()]);
QPalette p = contentFrame->palette();
p.setColor(QPalette::Button,color);
contentFrame->setPalette(p);
contentFrame->update();
}
void Palette::ShowButtonText()
{
QStringList colorList = QColor::colorNames();
QColor color = QColor(colorList[buttonTextComboBox->currentIndex()]);
QPalette p =contentFrame->palette();
p.setColor(QPalette::ButtonText,color);
contentFrame->setPalette(p);
}
void Palette::ShowBase()
{
QStringList colorList = QColor::colorNames();
QColor color = QColor(colorList[baseComboBox->currentIndex()]);
QPalette p = contentFrame->palette();
p.setColor(QPalette::Base,color);
contentFrame->setPalette(p);
}
void Palette::fillColorList(QComboBox *comboBox)
{
QStringList colorList = QColor::colorNames(); //(a) 获得QTList of color names for all built-in names.
QString color; //(b)
foreach(color,colorList) //Iterate over the list of color names
{
QPixmap pix(QSize(70,20)); //(c)
pix.fill(QColor(color)); //为pixFills the current traversal with the color
comboBox->addItem(QIcon(pix),NULL); //(d) 插入图标icon,名称设为NULL,i.e. the name of the color is not displayed
comboBox->setIconSize(QSize(70,20)); //(e) Set the size of the icon,默认是方形,将其设为和pixRectangles of the same size
comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
//(f) Sets the drop-down list box's resizing policy to :Fits the size of the content.
}
}
Palette::~Palette()
{
}
``
边栏推荐
- 金仓数据库KingbaseES安全指南--6.9. Ident身份验证
- md5sum源码 可多平台编译
- EpiSci|片上系统的深度强化学习:神话与现实
- Shell nl命令详解(显示行号、读取文件)
- Ali's official Redis development specification
- The site is not found after the website is filed. You have not bound this domain name or IP to the corresponding site! The configuration file does not take effect!
- B001 - 基于STM32的智能生态鱼缸
- 银行案例|Zabbix跨版本升级指南,4.2-6.0不香吗?
- When custom annotations implement log printing, specific fields are blocked from printing
- 2022年深圳市促进大健康产业集群高质量发展的若干措施
猜你喜欢
![[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails](/img/d7/4671b5a74317a8f87ffd36be2b34e1.jpg)
[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails

JumpServer堡垒机部署

ROS2支持技术:DDS简述

2022年SQL大厂高频实战面试题(详细解析)

机器学习快速入门

QLineEdit学习与使用

浅谈游戏音效测试点

hcip第九天

下载 | 谷歌科学家Kevin P. Murphy发布新书《概率机器学习:高级主题》

The anxiety of the post-90s was cured by the vegetable market
随机推荐
MySQL 45 讲 | 09 普通索引和唯一索引,应该怎么选择?
ROS2系列知识(6):Action服务概念
When custom annotations implement log printing, specific fields are blocked from printing
QT_事件类
opencv基本的图像处理
【R语言】批量重命名文件
浅谈游戏音效测试点
金仓数据库KingbaseES安全指南--6.5. LDAP身份验证
C语言:表达式求值详解
分布式消息队列平滑迁移技术实战
gtk显示4通道rgba图像
Pytorch|GAN在手写数字集上的复现
金仓数据库 KDTS 迁移工具使用指南(2. 简介)
关于MySql中explain结果filtered的理解
ROS2支持技术:DDS简述
tooltip control
QLineEdit学习与使用
统信软件、龙芯中科等四家企业共同发布《数字办公安全创新方案》
指针和解引用
SRM供应商管理系统如何助力口腔护理企业实现采购战略的转型升级