给自己的QT软件加上启动界面

想要给qt加上帅气的软件界面?直接替换下列图片地址就行

#include "mainwindow.h"

#include <QApplication>
#include <QSplashScreen>
#include <QLabel>
#include <QThread>
#include <QDesktopWidget>

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

    // 加载图片
    QPixmap pixmap("D:/HYX/HYX.jpg");

    // 设置图片的目标大小为400x400,并保持原本图片样式
    int targetWidth = 400;//只能决定最小值
    int targetHeight = 400;
    pixmap = pixmap.scaled(targetWidth, targetHeight, Qt::KeepAspectRatio);

    // 获取屏幕的宽度和高度
    int screenWidth = QApplication::desktop()->screenGeometry().width();
    int screenHeight = QApplication::desktop()->screenGeometry().height();

    // 设置图片的位置居中显示
    int x = (screenWidth - pixmap.width()) / 2;
    int y = (screenHeight - pixmap.height()) / 2;

    // 创建启动界面并显示图片
    QSplashScreen splash(pixmap);
    splash.setGeometry(x, y, pixmap.width(), pixmap.height());
    splash.show();

    // 设置启动界面文本
    QString version_full = "1.0";
    QLabel splashLabel("Ver " + version_full, &splash);
    splashLabel.setAlignment(Qt::AlignBottom);
    QFont serifFont("Arial", 10, QFont::Bold);
    splashLabel.setFont(serifFont);
    splashLabel.setStyleSheet("color: red");
    splashLabel.setGeometry(x, y + pixmap.height() - 30, pixmap.width(), 30);
    splashLabel.show();

    // 显示启动界面
    splash.show();
    a.processEvents();
    QThread::sleep(2);

    // 关闭启动界面
    splash.close();

    MainWindow w;
    w.show();
    return a.exec();
}
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值