qt 添加资源文件及使用qss

 

在Qt中读取资源文件中的文件方法

参考:

blog.sina.com.cn/s/blog_a671975e0101893v.html">blog.sina.com.cn/s/blog_a671975e0101893v.html

 

2 .ui文件添加一个QPushButton按钮

3 .创建一个.qss文件

打开写入

QPushButton{

    border:2px solid gray;
    border-radius: 10px;
}
QPushButton:hover{
    color:white;
    background:red;
}
添加到qrc文件
 

4.main.cpp代码:

#include "mainwindow.h"
#include 
#include 

int main(int argc, char *argv[])
{


    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    QFile styleFile(":/a.qss");
     styleFile.open(QIODevice::ReadOnly);
     QString setStyleSheet(styleFile.readAll());;
     a.setStyleSheet(setStyleSheet);
    return a.exec();
}

 

你可能感兴趣的:(qt)