QT样式表,StyleSheet()函数的使用
#include "mywidget.h"
#include "ui_mywidget.h"
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MyWidget)
{
ui->setupUi(this);
//this表示对整个窗口有效
this->setStyleSheet("QLabel{color:rgb(0, 255, 255);"//设置label文字颜色为靛蓝色
"background-color:red;"//设置label的背景色
"}");
//限制仅对label有效
ui->label->setStyleSheet("QLabel{color:rgb(0, 255, 255);"
"background-color:blue;" //设置label的背景色
// "background-image:url(:/new/prefix1/Sunny.jpg);" //添加图片
// "background-image:url(:/new/prefix1/sunny.png);" //添加图片,url中为图片路径
"border-image:url(:/new/prefix1/sunny.png);" //添加图片,url中为图片路径
"}");
ui->pushButton->setStyleSheet(
//默认
"QPushButton{border-image:url(:/new/prefix1/sunny.png);}"
//悬浮
"QPushButton:hover{border-image:url(:/new/prefix1/Luffy.png);}"
);
}
MyWidget::~MyWidget()
{
delete ui;
}
来源:https://www.cnblogs.com/luxinshuo/p/12230810.html