QT学习---通过三个滑动条控制textEdit的底色

#include 
#pragma execution_character_set("utf-8");


add::add(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);


	connect(ui.SliderRed, SIGNAL(valueChanged(int)), this, SLOT(on_SliderRed_valueChanged(int)));
	connect(ui.SliderGreen, SIGNAL(valueChanged(int)), this, SLOT(on_SliderRed_valueChanged(int)));
	connect(ui.SliderBlue, SIGNAL(valueChanged(int)), this, SLOT(on_SliderRed_valueChanged(int)));
	connect(ui.SliderAlpha, SIGNAL(valueChanged(int)), this, SLOT(on_SliderRed_valueChanged(int)));

}

void add::on_SliderRed_valueChanged(int value)
{
//	//拖动Red、Green、Blue颜色滑动条时设置textEdit的底色
	Q_UNUSED(value);
	QColor color;
	int R = ui.SliderRed->value();
	int G = ui.SliderGreen->value();
	int B = ui.SliderBlue->value();
	int alpha = ui.SliderAlpha->value();
	color.setRgb(R, G, B, alpha); //使用 QColor 的 setRgb ()函数获得颜色
	QPalette pal = ui.textEdit->palette();
	pal.setColor(QPalette::Base, color); //设置底色
	ui.textEdit->setPalette(pal);
}

可以不使用connect ,直接在设计师里面连接

你可能感兴趣的:(c++,QT学习)