[code=C/C++][/code]
- C/C++ code
#ifndef SHEET_H#define SHEET_H#include <QDialog>class QPushButton;class Sheet : public QDialog{ Q_OBJECTpublic: Sheet(QWidget *parent = 0);private: QPushButton *pushButton ;};#endif // SHEET_H
- C/C++ code
#include <QApplication>#include <QTextCodec>#include <QPushButton>#include <QFile>#include <QString>#include "sheet.h"Sheet::Sheet(QWidget *parent){ pushButton = new QPushButton("sheet",this);}int main(int argc,char **argv){ QApplication app(argc,argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312")); Sheet *sheet = new Sheet; QFile qss("C://style.qss"); //这个是绝对路径,,,用的是XP 系统,,编译能通过,就是没有效果,, qss.open(QFile::ReadOnly); qApp->setStyleSheet(qss.readAll()); qss.close(); sheet->setVisible(true); return app.exec();}
qss:
QPushButton#pushButton
{
color : red;
}
------解决方案--------------------
你把style.qss copy到工程顶层目录先试试
QFile qss("style.qss");
一定可以读到,再排查错误