一、应用程序中文化
1).Qt安装目录下有一个目录translations/,在此目录下有qt_zh_CN.ts和 qt_zh_CN.qm
把它们拷贝到你的工程目录下。
2).在main函数加入下列代码:
QTranslator translator(0);
translator.load("qt_zh_CN.qm");
QApplication app(argc, argv);
app.installTranslator(&translator);
别忘了头文件包含QTranslator
二、应用程序实现重启
void CGUIfeaturesList::on_restartBtn_clicked()
{
qApp->quit();
QProcess::startDetached(qApp->applicationFilePath(), QStringList());
}
三、使用QSS样式表文件
QFile file("./style.qss");
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
qApp->setStyleSheet(styleSheet);
file.close();
四、使用程序启动界面
QPixmap pixmap("./start.png");
QSplashScreen splash(pixmap);
splash.show();
QTime dieTime = QTime::currentTime().addMSecs(3000);
while( QTime::currentTime() < dieTime )
a.processEvents(QEventLoop::AllEvents, 100);
MainWindow w;
w.move((QApplication::desktop()->width() - w.width())/2,(QApplication::desktop()->height() - w.height())/2);
w.show();
splash.finish(&w);
main.cpp文件参考如下:
#include <QTextCodec>
#include <QPixmap>
#include <QSplashScreen>
#include <QTime>
#include <QTextCodec>
#include <QFile>
#include <QTranslator>
#include <QtGui>
int main(int argc, char *argv[])
{
QTranslator translator(0);//标准对话框中文化
translator.load("qt_zh_CN.qm");
QApplication a(argc, argv);
a.installTranslator(&translator);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
// QTextCodec::setCodecForTr(QTextCodec::codecForName(QTextCodec::codecForLocale()->name()));
// QTextCodec::setCodecForLocale(QTextCodec::codecForName(QTextCodec::codecForLocale()->name()));
// QTextCodec::setCodecForCStrings(QTextCodec::codecForName(QTextCodec::codecForLocale()->name()));
QFile file("./style.qss");
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
qApp->setStyleSheet(styleSheet);
file.close();
QPixmap pixmap("./start.png");
QSplashScreen splash(pixmap);
splash.show();
QTime dieTime = QTime::currentTime().addMSecs(3000);
while( QTime::currentTime() < dieTime )
a.processEvents(QEventLoop::AllEvents, 100);
CGUIfeaturesList w;
w.move((QApplication::desktop()->width() - w.width())/2,(QApplication::desktop()->height() - w.height())/2);
w.show();
splash.finish(&w);
return a.exec();
}
http://blog.csdn.net/liuguangzhou123/article/details/8079996