在Qt里使用QSplashScreen类制作Splash启动窗口
转自:http://hi.baidu.com/xchinux/item/1f756d297f8ec8f950fd8796
发现在Qt论坛(http://www.qtcn.org)里有几个关于这方面的问题,其实这个问题即使不使用QSplashScreen也是很好解决的,就是一个简单的无边框(标题栏)的窗口,自己控制其显示就行了。(我指的是Qt4 OpenSource版)
在Qt4中,可使用QSplashScreen来方便地制作启示窗口。在文档中已经给了个例子了。
下面我帖一下我自己试验的。
#include <QtGui/QtGui>
#include <QtGui/QPixmap>
#include <QtGui/QSplashScreen>
#include "ui_browser.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPixmap pixmap("splash.png");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->show();
QMainWindow *form = new QMainWindow;
Ui::MainWindow ui;
ui.setupUi(form);
ui.textBrowser->setSource(QString("files:///C:/Qt/4.1.2/doc/html/index.html"));
form->show();
splash->finish(form);
delete splash;
return app.exec();
}
而采用计时器来控制显示时间的话,可用下面方法自己制作SplashWindow。
注意,我里面只是使用了简单的QDialog来代替SplashWindow,使用的时候可自己用它来制作自己需要的SplashWindow
#include <QtGui/QtGui>
#include <QtGui/QDialog>
#include <QtCore/QTimer>
#include "ui_browser.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QDialog dialog;
QMainWindow *form = new QMainWindow;
Ui::MainWindow ui;
ui.setupUi(form);
ui.textBrowser->setSource(QString("files:///C:/Qt/4.1.2/doc/html/index.html"));
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), form, SLOT(show()));
QObject::connect(&timer, SIGNAL(timeout()), &dialog, SLOT(accept()));
timer.start(10000);
dialog.exec();
return app.exec();
}
openvela 操作系统专为 AIoT 领域量身定制,以轻量化、标准兼容、安全性和高度可扩展性为核心特点。openvela 以其卓越的技术优势,已成为众多物联网设备和 AI 硬件的技术首选,涵盖了智能手表、运动手环、智能音箱、耳机、智能家居设备以及机器人等多个领域。
更多推荐


所有评论(0)