1、使用步骤:
(1)第一步:
将文件拷贝至相应的工程文件下
(2)第二步:
打开工程,修改文件中的main函数的文件:(截图红色部分为关键代码所示)
#include "widget.h"
#include <QFrame>
#include <QApplication>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile file("./style.qss");
if(file.open(QFile::ReadOnly))
{
a.setStyleSheet(file.readAll());
file.close();
}
else
{
qDebug()<<"open file error";
}
Widget w;
w.show();
return a.exec();
}
note:
.qss文件在最后添加
2、内容
QWidget{
background: white; //画面背景
}
QPushButton //正常情况下按钮
{ color:#CCFFFF;
background-color:#CC66FF;
border-radius:5px;
font:bold 12px;
padding:4px;
font-size:18px;
}
QPushButton:hover { //鼠标悬浮情况下按钮
background-color: #333333;
border-color: #444444;
}QPushButton:pressed { //鼠标按压情况下按钮
background-color: #111111;
border-color: #333333;
color: yellow;
}
QSlider //滑块
{
background: #eee;
border: 1px solid #aaa;
border-radius: 4px;
}