想要给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();
}