QT實現(xiàn)提示右下角冒泡效果
更新時間:2020年08月20日 10:35:55 作者:swartz_lubel
這篇文章主要為大家詳細介紹了QT實現(xiàn)提示右下角冒泡效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了QT實現(xiàn)提示右下角冒泡的具體代碼,供大家參考,具體內(nèi)容如下
實現(xiàn)原理:
1、顯示
定時器啟動,右下角緩慢彈出,逐漸改變位置。
2、駐留
讓界面停留一定的時間,時間過后自動關閉。
3、退出
可以直接點擊關閉退出,也可以采用改變透明度的形式模糊退出。
#ifndef _QTOOLTIPS_ #define _QTOOLTIPS_ #include <QTimer> #include <QDialog> #include "ui_QToolTips.h" class QToolTips:public QDialog { Q_OBJECT public: 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 <QtWidgets/QApplication> #include <QDesktopWidget> 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); } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關文章
Opencv基于CamShift算法實現(xiàn)目標跟蹤
這篇文章主要為大家詳細介紹了Opencv基于CamShift算法實現(xiàn)目標跟蹤,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01C++調(diào)用libcurl開源庫實現(xiàn)郵件的發(fā)送功能流程詳解
libcurl是一個免費開源的網(wǎng)絡傳輸庫,支持ftp、ftps、tftp,http、https、telnet、ldap、pop3、smtp等多種協(xié)議,接下來讓我們一起來了解吧2021-11-11