博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QT 提示之右下角冒泡
阅读量:4167 次
发布时间:2019-05-26

本文共 1919 字,大约阅读时间需要 6 分钟。

实现原理

  1.  显示
      定时器启动,右下角缓慢弹出,逐渐改变位置
  2. 驻留
      让界面停留一定的时间,时间过后自动关闭。
  3. 退出
    可以直接点击关闭退出,也可以采用改变透明度的形式模糊退出。
#ifndef _QTOOLTIPS_#define _QTOOLTIPS_#include 
#include
#include "ui_QToolTips.h"class QToolTips:public QDialog{ Q_OBJECTpublic: QToolTips(QWidget *parent = 0); ~QToolTips(); void showMessage(const char* str);private slots: void onMove(); void onStay();- void onClose();private: Ui::QToolTips ui; QTimer * m_pShowTimer; QTimer * m_pStayTimer; QTimer * m_pCloseTimer; QPoint m_point; int m_nDesktopHeight; double m_dTransparent;};#endif
#include "QToolTips.h"#include 
#include
QToolTips::QToolTips(QWidget *parent /*= 0*/) : QDialog(parent){ setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); ui.setupUi(this); m_nDesktopHeight = QApplication::desktop()->height(); m_dTransparent = 1.0; m_pShowTimer = new QTimer(this); m_pStayTimer = new QTimer(this); m_pCloseTimer = new QTimer(this); connect(m_pShowTimer, SIGNAL(timeout()), this, SLOT(onMove())); connect(m_pStayTimer, SIGNAL(timeout()), this, SLOT(onStay())); connect(m_pCloseTimer, SIGNAL(timeout()), this, SLOT(onClose()));}QToolTips::~QToolTips(){ }void QToolTips::showMessage(const char* str){ ui.m_label->setStyleSheet("background-color:rgb(255,210,200);font:60px;color:blue"); ui.m_label->setText(str); QRect rect = QApplication::desktop()->availableGeometry(); m_point.setX(rect.width() - width()); m_point.setY(rect.height() - height()); move(m_point.x(), m_point.y()); m_pShowTimer->start(5);}void QToolTips::onMove(){ m_nDesktopHeight--; move(m_point.x(), m_nDesktopHeight); if (m_nDesktopHeight <= m_point.y()) { m_pShowTimer->stop(); m_pStayTimer->start(5000); }}void QToolTips::onStay(){ m_pStayTimer->stop(); m_pCloseTimer->start(100);}void QToolTips::onClose(){ m_dTransparent -= 0.1; if (m_dTransparent <= 0.0) { m_pCloseTimer->stop(); close(); } else { setWindowOpacity(m_dTransparent); }}

转载地址:http://dvqxi.baihongyu.com/

你可能感兴趣的文章
mysql 赋给用户权限 grant all privileges on
查看>>
读取文件的几种方法
查看>>
yast 创建本地数据源
查看>>
vim 编码方式(encoding、fileencoding、fileencodings、termencoding介绍)
查看>>
程序员的十层楼
查看>>
windows 下php支持curl
查看>>
获取文件夹文件(C++)
查看>>
判断文件夹是否存在
查看>>
快速的内存分配器
查看>>
java中super 的两种用法
查看>>
bdb及其在php下扩展的安装
查看>>
bdb及其在php下扩展的安装
查看>>
android 小问题
查看>>
BerkeleyDB安装及配置
查看>>
标准的Activity Actions
查看>>
关于Android requires .class compatibility set to 5.0. Please fix project properties.的错误
查看>>
JAVA中implements实现多接口
查看>>
android中导入低版本project可能会遇到的编译问题
查看>>
showDialog
查看>>
Flex 拖拽范例
查看>>