Qt设置启动画面和广告画面
来源:互联网 发布:彝族音乐 知乎 编辑:程序博客网 时间:2024/04/29 04:09
Qt之启动画面
目前的手机应用都是有启动画面的,但是PC端软件的基本没有启动画面,移动端还是比较常见的,在相继开发了几款APP之后,总结一下Qt启动画面的设置方法,也许启动画面的设置方法还有很多,下面总结一下个人所使用的几种方法:
1. TheQSplashScreen widget provides a splash screen that can be shown duringapplication startup.
这个是Qt手册的原文,我们利用Qt提供便捷的启动画面类来实现启动画面,实现启动画面,根据手册提示有几种方式,我只使用了其中的两种。
//2.启动画面
//2.1一级启动画面
QPixmap pixmap(":/Resources/start.jpg"); pixmap.scaled(QApplication::desktop()->availableGeometry().size(),Qt::KeepAspectRatio);QSplashScreen m_screen(pixmap); m_screen.move(0,0);m_screen.setDisabled(true);//禁止界面输入事件m_screen.show();QDateTime n=QDateTime::currentDateTime(); QDateTime now; do{ now=QDateTime::currentDateTime(); a.processEvents(); } while (n.secsTo(now)<=3);</span>
...........m_screen.close();</span>
这是一种方法,main函数中添加即可。
2. QSplashScreensupports this with the showMessage() function. If you wish to do your owndrawing you can get a pointer to the pixmap used in the splash screen withpixmap(). Alternatively, you can subclass QSplashScreen and reimplementdrawContents().
这个是第二中方法原文:
实现过程如下:
我们要子类化QsplashScreen,这样我们就可以将二级启动画面作为广告画面了.
<pre name="code" class="cpp">/*-------------------------------------------------------- @Purpose:实现启动画面 @Time:2016.6.6 @Author:QFGL ----------------------------------------------------------*/ #include <QSplashScreen> #include <QLabel> #include <QString> #include <QPushButton>class CSplashScreen : public QSplashScreen { Q_OBJECT public: explicit CSplashScreen(QPixmap& pixmap,int time); ~CSplashScreen(void); private: //1.加载启动画面 void LoadPhoto();private slots://2.倒计时void CountDown();public: //倒计时值 int interval;//记录倒计时剩余值qint32 m_Time;public: //标签类 QLabel *m_Label; //二级广告画面显示按钮 QPushButton *m_PushButton; };
#include "QFSplashScreen.h" #include <stdlib.h> #include <windows.h> #include "stdafx.h"CSplashScreen::CSplashScreen(QPixmap& pixmap,int reducetime) : QSplashScreen(pixmap),interval(reducetime) { m_PushButton = new QPushButton(this); m_Label= new QLabel(m_PushButton);m_PushButton->setGeometry(pixmap.width()-100,0,100,30); m_PushButton->setText("SKIP"); m_PushButton->setStyleSheet("QPushButton{color:blue;font:18px;text-align:center;border:none }QPushButton::chunk {background-color: rgba(0, 0, 0,0);}"); m_PushButton->setStyleSheet("QLabel{color:blue;font:30px;text-align:center;}QLabel::chunk {background-color: rgba(0, 0, 0,0);}"); m_Time=3;LoadPhoto(); } CSplashScreen::~CSplashScreen(void) { } //启动画面 void CSplashScreen:: LoadPhoto() { qint32 iTime = interval/2.5; for (qint32 i = 0; i < 3; i++) { QTimer::singleShot(i*iTime,this,SLOT(CountDown())); } QTimer::singleShot(interval,this,SLOT(close())); } //倒计时void CSplashScreen::CountDown(){QString sTime, m_timeString;m_timeString = sTime.number(m_Time,10);m_Label->setText(m_timeString);m_timeString.clear();m_Time--;}
我们可以将这个子类作为广告画面,这样就有倒计时显示了,但是SKIP大家要自己添加接口,就不再赘述了,具体如何使用就看项目情况了,就简单介绍到这。
注:如果大家要添加GIF广告或者启动画面,就要使用QMovie这个类,具体如何使用可以看一下文档了!下一篇将推出浅谈Qt、MFC之GUI编程架构。
这个就是简单的两种使用方法了,如果有什么错误,请联系QFGL:2120263292- Qt设置启动画面和广告画面
- Qt启动画面设置
- QT 添加启动画面
- Qt的启动画面
- Qt 启动画面
- QT 启动画面
- Qt实现启动画面
- Qt程序启动画面
- qt启动画面实现
- QSplashScreen设置启动画面
- MFC 设置启动画面
- IOS 启动画面设置
- IOS 启动画面设置
- iOS 启动画面设置
- MFC设置启动画面
- IOS 启动画面设置
- IOS 启动画面设置
- Android设置启动画面
- 第九条: equals和hashCode
- 论文笔记:Network in Network
- java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
- Android java.lang.RuntimeException: Can't create handler inside thread that has not called
- Hive高级进阶与优化
- Qt设置启动画面和广告画面
- C语言常见命名规范
- Excel解析
- JAVA从菜鸟【入门】到新手【实习】一一ASP技术的若干思考
- HashMap常见面试题(完善中)
- 基于Theano的深度学习(Deep Learning)框架Keras学习随笔-05-模型
- oracle v_$session和v$session
- 为select选择框增加滚动条
- 携程移动端架构演进与优化之路