一般步骤
- 在程序主入口函数中创建QSplashScreen对象,并且为其分配图片资源
- 设置需要显示的message
- 使程序在显示启动画面的同时仍能响应鼠标等事件,a.processEvents();
- 调用QSplashScreen对象的finish()方法,等待主程序加载完成,结束启动画面
经典代码
int main(int argc, char *argv[])
{
QApplication a(argc, argv)
//设置启动页
QPixmap pixmap("circle_purple.png")
pixmap = pixmap.scaled(400,400,Qt::KeepAspectRatio)
QSplashScreen splash(pixmap)
splash.setFont((QFont("Helvetica", 34, QFont::Bold)))
splash.showMessage("loading",Qt::AlignCenter,QColor::fromRgb(255,10,255))
splash.show()
splash.setCursor(Qt::BlankCursor)
a.processEvents()
splash.showMessage("QT",Qt::AlignCenter,QColor::fromRgb(255,10,255))
splash.showMessage("RC",Qt::AlignCenter,QColor::fromRgb(255,10,255))
MainWindow w
w.show()
splash.finish(&w)
return a.exec()
}