如何设置控件、标签、按钮 字体大小和背景颜色?
以下提供几种方法可供参考:
一、使用setPalette()方法
二、使用样式表setStyleSheet()
第一种,使用setPalette()方法如下:
QPalette pe;
pe.setColor(QPalette::WindowText, Qt::red);
QLabel *label = new QLabel(this);
label->setPalette(pe);
label->setText("Hello World");
第二种,使用样式表setStyleSheet()方法如下:
setStyleSheet("background-color:DeepSkyBlue;font-size:40px;color:white")
依次是:背景颜色-字体大小-字体颜色
//登录按钮
this->BtnLogin=new QPushButton("登陆",this);
this->BtnLogin->setStyleSheet("background-color:DeepSkyBlue;font-size:40px;color:white");
this->BtnLogin->setGeometry(185,505,400,65);
效果图: