Qt开发——QSplashScreen程序启动图

目录

效果图

官方手册摘录:

main.cpp

mainwindow.cpp

mainwindow.h


效果图

官方手册摘录:

https://doc.qt.io/qt-5/qsplashscreen.html#details

main.cpp

#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QSplashScreen>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QPixmap pixmap("screen.png");
    QSplashScreen splash(pixmap);
    splash.show();
    a.processEvents();//使程序显示启动时仍能响应鼠标等其他时间
    MainWindow w;
    w.show();
    splash.finish(&w);//在主窗体对象完成初始化之后结束启动画面

    return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle(QStringLiteral("程序启动后画面"));
    setWindowIcon(QIcon("icon.png"));
    QTextEdit *edit=new QTextEdit;
    edit->setText(QStringLiteral("已经正常启动……"));
    setCentralWidget(edit);
    resize(600,800);
    Sleep(1000);
}

MainWindow::~MainWindow()
{

}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QString>
#include <QTextEdit>
#include <Windows.h>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
};

#endif // MAINWINDOW_H
发布了232 篇原创文章 · 获赞 205 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_41895747/article/details/104057013