Fork me on GitHub

Qt之对话框设计——程序启动界面

在main.cpp中实例化一个QSplashScreen对象,加载启动画面,并显示该对象。当主窗口打开后,终结(finis)该对象。


mainwin.h

#ifndef MAINWIN_H
#define MAINWIN_H

#include <QtGui/QMainWindow>


class MainWin : public QMainWindow
{
	Q_OBJECT

public:
	MainWin(QWidget *parent = 0, Qt::WFlags flags = 0);
	~MainWin();
	
private:
	
};

#endif // MAINWIN_H

mainwin.cpp

#include "mainwin.h"
#include <QTextEdit>
#include <QElapsedTimer>
#include <QCoreApplication>


MainWin::MainWin(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	setWindowTitle(tr("Splash Screen Example"));

	QTextEdit *edt = new QTextEdit;
	edt->setText("Splash Screen Example!");
	setCentralWidget(edt);
	
	resize(600,450);


	QElapsedTimer t;
	t.start();
	while(t.elapsed()<1000)
	QCoreApplication::processEvents();	
}

MainWin::~MainWin()
{

}

main.cpp

#include "mainwin.h"
#include <QtGui/QApplication>
#include <QPixmap>
#include <QSplashScreen>

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

	QPixmap pix("images/splash.jpg");
	QSplashScreen splash(pix);
	splash.show();
	a.processEvents();

	MainWin w;
	w.show();
	splash.finish(&w);

	return a.exec();
}
posted @ 2012-11-23 18:38  韩兆新  阅读(2944)  评论(0编辑  收藏  举报