• 17731阅读
  • 7回复

在Qt里使用QSplashScreen类制作Splash启动窗口 [复制链接]

上一主题 下一主题
离线XChinux
 

只看楼主 倒序阅读 楼主  发表于: 2006-04-04
发现在论坛里有几个关于这方面的问题,其实这个问题即使不使用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();
}
[ 此贴被XChinux在2006-04-04 12:36重新编辑 ]
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线guyansrg

只看该作者 1楼 发表于: 2006-04-15
谢谢啦,又学到一些好东东
离线ywchen2000

只看该作者 2楼 发表于: 2006-04-16
老大真好.
ipanforlinux 金山快盘LINUX版本
qnotepad  一个功能强大的文本编辑器
欢迎访问http://www.ipanx.net
离线计科院
只看该作者 3楼 发表于: 2009-04-04
#include<QtGui>
class timer: public QWidget
{
   Q_OBJECT
   public:
      timer();
      ~timer();
   private:
      void intconect();
   private slots:
      void timeoutdo();
};

#include<QtGui>
#include <QPixmap>
#include<QSplashScreen>

#include<timer.h>

timer::timer()
{
   //QObject::connect(time, SIGNAL(timeout()), this, SLOT(timeoutdo()));
   intconect();
   timeoutdo();
  
}

timer::~timer()
{
  
}
void timer::intconect()
{
   QObject::connect(time, SIGNAL(timeout()), this, SLOT(timeoutdo()));
}

void timer::timeoutdo()
{
    time->start(5000);
    QPixmap foreground("image/startScreen.jpg");
    QSplashScreen *screen= new QSplashScreen;
    screen->setPixmap(foreground);
    screen->setGeometry(QRect(0, 50, 640, 480));
    screen->show();
    screen->showMessage("载入中,请稍候........",Qt::AlignCenter,Qt::white);
    timer->stop();
}

主函数调用QTimer timer;
  timer.start(10000);

但是还是没有看到那个画布停了几秒
清斑竹帮帮忙
离线计科院
只看该作者 4楼 发表于: 2009-04-05
请请斑竹解决下我这个问题
        万分感谢!!!!
离线soros
只看该作者 5楼 发表于: 2009-10-24
我是这样做的:
QApplication a(argc, argv);
QMainWindow w;

QPixmap picture(":/Resource/images/girl.png");
QSplashScreen splash(picture);
splash.show();

QTimer::singleShot(2100, &splash, SLOT(close()));
QTimer::singleShot(2000, &w, SLOT(show()));
-----------------------------------------------------------------------
设置2.1s后splash关闭,2s后QMainWindow显示,时间上差不多就可以了,人眼是有错觉的。
离线bean
只看该作者 6楼 发表于: 2010-05-17
能不能请教一个问题啊?我刚刚学习qt,不知道怎么改

#include "changevalue.h"

#include <QtGui>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    changeValue w;
    w.show();
   QTimer * timer = new QTimer(w);
    connect( &timer, SIGNAL(timeout()), w, SLOT(changeVal()) );
    timer->start(100);

    return a.exec();
}
期中slot changeVal()是我自己写的,但是出现了如下错误

no matching function for call to 'QTimer::QTimer(changeValue&)'    main.cpp    /changeValue    line 11    C/C++ Problem

no matching function for call to 'changeValue::connect(QTimer**, const char*, changeValue&, const char*)'    main.cpp    /changeValue    line 12    C/C++ Problem


这个怎么解决啊?谢谢啦!
离线xinqingfly

只看该作者 7楼 发表于: 2010-05-18
connect前加上QObject::
菜鸟也是鸟
快速回复
限100 字节
 
上一个 下一个