新建一个widget的项目
在widget.ui上面拉三个控件
在源码目录中新建一个pro.qss文件
QPushButton{
/*background-color: #473C8B; /*背景色*/
border-style: outset;
border-width: 2px;
border-radius:5px; /*边界圆滑*/
border-color: #8B7355;
font: bold 20px;
min-width:2em;
color:#000000; /*字体颜色*/
font-family:华文新魏;
padding: 5px;
}
QWidget{
border: 1px solid rgb(255,0,0);
}
在主函数中写入
#include "widget.h"
#include <QApplication>
#include <QFile>
#include <QTextStream>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile file("../pro.qss");
if(!file.open(QFile::ReadOnly)){
qDebug() << "open pro file";
}
QTextStream filetext(&file);
QString stylesheet = filetext.readAll();
qApp->setStyleSheet(stylesheet);
file.close();
Widget w;
w.show();
return a.exec();
}