qt中使用启动画面
来源:互联网 发布:中国汽车 知乎 编辑:程序博客网 时间:2024/06/07 21:06
在程序打开的时候,启动画面是很正常的。
对于这个qt提供了QSplashScreen类,可是我在使用过程中,他总是一闪而过,不是我们想要的。我们使用启动画面,如果没有模块检测,那我们只是想它显示几秒钟而已。下面是我的办法,继承QSplashScreen,在加个定时器就行了。
#ifndef SPLASHSCREEN_H
#define SPLASHSCREEN_H
#include <QSplashScreen>
#include <QTimer>
class splashScreen : public QSplashScreen
{
Q_OBJECT
public:
explicit splashScreen(const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0);
// splashScreen(QWidget * parent, const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0);
void setShowSecond(int _second);//设置启动画面的显现时长,单位是秒,不是微秒
void startTimer() {show();timer.start();}//定时器开始工作
signals:
void timeOver();//达到规定的显示时长发出此信号
public slots:
protected slots:
void stopTimer();//关闭定时器
private:
~splashScreen(){}
QTimer timer;//显示时长定时器
};
#endif // SPLASHSCREEN_H
#include "splashscreen.h"splashScreen::splashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :QSplashScreen(pixmap,f){
}
//splashScreen::splashScreen(QWidget * parent, const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0):// QSplashScreen(parent, pixmap, f)//{
//}
void splashScreen::setShowSecond(int _second){
timer.setInterval(_second*1000);connect(&timer,SIGNAL(timeout()),this,SLOT(stopTimer()));}
void splashScreen::stopTimer(){
timer.stop();emit timeOver();close();deleteLater();//此处是特意添加,只能在一次使用,且只能是在heap区使用}
int main(int argc, char *argv[]){
QApplication a(argc, argv);QPixmap pix(":/picture/splashScreen.jpg");splashScreen *ps = new splashScreen(pix);ps->setShowSecond(3);ps->startTimer();MainWindow w;QObject::connect(ps,SIGNAL(timeOver()),&w,SLOT(show()));w.resize(QApplication::desktop()->size()*0.9);//以设备的显示器件的大小来确定主界面的大小return a.exec();}为什么我想在启动画面结束之后之后直接释放,因为它就是这时候有用,我不想在程序运行结束的时候在释放,资源是宝贵的。还有就是默认的鼠标点击操作是hide()。如果你不想不小心点了鼠标画面消失,并且主界面还没有出来,还是重写void mousePressEvent(QMousePressEvent *),函数体为空就行。
- qt中使用启动画面
- Qt中实现启动画面
- Qt中开机启动画面
- Qt中实现启动画面
- Qt 程序启动画面QSplashScreen的使用
- QT使用GIF作程序启动画面
- QT 添加启动画面
- Qt的启动画面
- Qt 启动画面
- QT 启动画面
- Qt实现启动画面
- Qt启动画面设置
- Qt程序启动画面
- qt启动画面实现
- Qt设置启动画面和广告画面
- QT添加程序启动画面
- 实现Qt程序启动画面
- qt添加程序启动画面
- 在linux下利用autotools创建makefile文件
- CYGWIN BUILD exe方法。比较适合尝试一些小的算法
- Mysql 查看连接数,状态
- sql语言基本学习笔记(一)
- sscanf的用法
- qt中使用启动画面
- CreateEvent的用法
- 2012_7_27
- hdu 4318 Power transmission
- 游标——SQL server
- 重载运算符实现精简版string类
- eclipse+CDT+VC6.0
- matlab并行运行环境设置
- HDU 4318 Power transmission(最短路变形)