QT屏幕保护程序二
来源:互联网 发布:那个基金软件好 编辑:程序博客网 时间:2024/05/22 09:45
前面我们用继承QApplication的方式实现了屏幕保护,
接下了用第二种方式:
首先定义一个屏保类:
#ifndef SPLASHSCREEN_H#define SPLASHSCREEN_H#include <QWidget>#include "mainwindow.h"namespace Ui {class SplashScreen;}class SplashScreen : public QWidget{ Q_OBJECTpublic: explicit SplashScreen(QWidget *parent = 0); ~SplashScreen();protected: void keyPressEvent(QKeyEvent *e);private: Ui::SplashScreen *ui;};#endif // SPLASHSCREEN_H
cpp.文件
#include "splashscreen.h"#include "ui_splashscreen.h"#include <QImage>#include <QDebug>SplashScreen::SplashScreen(QWidget *parent) : QWidget(parent), ui(new Ui::SplashScreen){ ui->setupUi(this); QImage *image = new QImage(":/style/ui_image/load.png"); ui->label->setPixmap(QPixmap::fromImage(*image));}SplashScreen::~SplashScreen(){ delete ui;}void SplashScreen::keyPressEvent(QKeyEvent *e){ this->hide(); ((MainWindow*)this->parentWidget())->currentWidgetChanged(3);}
主函数中:
QApplication app(argc, argv);
MainWindow mainWin;mainWin.show();
app.installEventFilter(&mainWin);
return app.exec();将mainWin注册一个焦点过滤事件,写一个定时器的槽函数
mainwindow.h文件中添加:
private slots:
void splashTimeTimeoutSlot();
protected:
bool eventFilter(QObject *obj, QEvent *event);private:QWidget *pSplashTimeWidget = Q_NULLPTR;//定义一个计时器,多久进入屏幕保护//重写过滤事件函数QTimer splashTime;
mainwindow.cpp文件中实现两个函数:
在mainwindow的构造函数中:
pSplashTimeWidget = new SplashScreen(this);pSplashTimeWidget->hide();//实例化并隐藏connect(&splashTime,SIGNAL(timeout()),this,SLOT(splashTimeTimeoutSlot()));
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
// if(sysInfo.sleeptime = "")
// {
splashTime.start(5000);
}
return QObject::eventFilter(obj, event);
}
void MainWindow::splashTimeTimeoutSlot(){pSplashTimeWidget->show();pSplashTimeWidget->grabKeyboard();}
阅读全文
0 0
- QT屏幕保护程序二
- QT关于屏幕保护程序
- QT关于屏幕保护程序
- 屏幕保护程序
- c#屏幕保护程序
- 用VB制作屏幕保护程序
- 深入浅出屏幕保护程序编程
- 屏幕保护程序制作基础
- 改编的一个屏幕保护程序
- 用汇编编写屏幕保护程序
- 如何启动屏幕保护程序
- 如何停止屏幕保护程序?
- Windows屏幕保护程序的制作
- 金锋屏幕保护程序 bt
- 用VB制作屏幕保护程序
- 利用VB编写屏幕保护程序
- 4.2.2 屏幕保护程序
- 4.2.2 屏幕保护程序
- 做一个自己的WiFi密码查看器——Android
- 普通Api和RESTful Api的区别
- 职业规划
- 新路程------hi3516a 内置rtc调试
- JAVA基础学习
- QT屏幕保护程序二
- 这个房间有点温馨--幸福梦负氧离子墙衣
- android自定义布局中的平滑移动(转)
- UVA-524 素数环 回溯
- Ubuntu安装NVIDIA驱动失败解决:登陆界面重复登录
- ng中infinite-scroll插件无限请求问题解决方法
- ajax如何请求本地txt文件时
- 看了一系列关于 JVM 的文章,非常好,记录一下地址
- 用java写邮箱发送的小案例