• 8466阅读
  • 1回复

【提问】求一个Qt 4下的程序起动时载入splash图象的例子。 [复制链接]

上一主题 下一主题
离线kytexzy
 

只看楼主 倒序阅读 楼主  发表于: 2005-09-07
小弟我新学Qt,想求一个程序起动时载入splash图象的例子的,还请高人不吝赐教!
[ 此贴被XChinux在2005-09-07 23:39重新编辑 ]
try to find forgiveness for yourself and forgive others
离线XChinux

只看该作者 1楼 发表于: 2005-09-07
源代码包含七个源文件main.cpp是主函数。ex65.h和ex65.cpp,还有ex65.ui是主窗体文件,splashwindow.h, splashwindow.cpp和splashwindow.ui是Splash窗口。
在启动时,Splash窗口先出现,在用户点击用鼠标在窗口上点击一下后,Splash窗口消失,主窗口显示。

main.cpp
#include <QtGui/QApplication>
#include "ex65.h"
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  ex65 w;
  //w.show();
  a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
  return a.exec();
}


ex65.h
#ifndef EX65_H
#define EX65_H

#include <QtGui/QWidget>
#include "ui_ex65.h"
#include "splashwindow.h"

class ex65 : public QWidget
{
  Q_OBJECT

public:
  ex65(QWidget *parent = 0);
  ~ex65();

private:
  Ui::ex65Class ui;
    SplashWindow *sp;
};

#endif // EX65_H


ex65.cpp
#include "ex65.h"
#include "splashwindow.h"

ex65::ex65(QWidget *parent)
  : QWidget(parent)
{
    ui.setupUi(this);
    sp = new SplashWindow(this);
    sp->show();
}

ex65::~ex65()
{
    delete sp;
}


splashwindow.h
#ifndef SPLASHWINDOW_H
#define SPLASHWINDOW_H

#include <QDialog>
#include <QMouseEvent>
#include "ui_splashwindow.h"

using namespace Ui;

class SplashWindow : public QDialog, public SplashWindowClass
{
  Q_OBJECT

public:
  SplashWindow(QWidget *parent = 0);
  ~SplashWindow();
private:
    void mousePressEvent(QMouseEvent *);
};

#endif // SPLASHWINDOW_H


splashwindow.cpp
#include <QImage>
#include <QPixmap>
#include "splashwindow.h"


SplashWindow::SplashWindow(QWidget *parent)
: QDialog(parent)
{
  setupUi(this);
    QImage image("splash.png");
    label->setPixmap(QPixmap::fromImage(image));
    resize(500, 375);
    setWindowFlags(Qt::SplashScreen);
}

SplashWindow::~SplashWindow()
{
}

void SplashWindow::mousePressEvent(QMouseEvent *e)
{
    close();
    QWidget *parent = this->parentWidget();
    parent->show();
}


ex65.ui
<UI version="4.0" stdSetDef="1" >
<class>ex65Class</class>
<widget class="QWidget" name="ex65Class" >
<property name="objectName" >
  <cstring>ex65Class</cstring>
</property>
<property name="geometry" >
  <rect>
  <x>0</x>
  <y>0</y>
  <width>600</width>
  <height>482</height>
  </rect>
</property>
<property name="windowTitle" >
  <string>ex65</string>
</property>
</widget>
<layoutDefault spacing="6" margin="11" />
</UI>


splashwindow.ui
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>SplashWindowClass</class>
<widget class="QWidget" name="SplashWindowClass" >
<property name="geometry" >
  <rect>
  <x>0</x>
  <y>0</y>
  <width>382</width>
  <height>266</height>
  </rect>
</property>
<property name="windowTitle" >
  <string>SplashWindow</string>
</property>
<layout class="QGridLayout" >
  <property name="margin" >
  <number>8</number>
  </property>
  <property name="spacing" >
  <number>6</number>
  </property>
  <item row="0" column="0" >
  <widget class="QLabel" name="label" />
  </item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>


附件中是源代码和截图
附件: ex65.rar (385 K) 下载次数:32
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个