QT實(shí)現(xiàn)提示右下角冒泡效果
本文實(shí)例為大家分享了QT實(shí)現(xiàn)提示右下角冒泡的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)原理:
1、顯示
定時(shí)器啟動(dòng),右下角緩慢彈出,逐漸改變位置。
2、駐留
讓界面停留一定的時(shí)間,時(shí)間過(guò)后自動(dòng)關(guān)閉。
3、退出
可以直接點(diǎn)擊關(guān)閉退出,也可以采用改變透明度的形式模糊退出。
#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);
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Qt實(shí)現(xiàn)繪制網(wǎng)格背景的示例代碼
這篇文章主要介紹了Qt如何實(shí)現(xiàn)繪制網(wǎng)格背景,并且能實(shí)現(xiàn)窗口大小調(diào)整時(shí)網(wǎng)格背景也自動(dòng)調(diào)整重繪,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-06-06
Linux下C語(yǔ)言的幾道經(jīng)典面試題小結(jié)(分享)
下面小編就為大家?guī)?lái)一篇Linux下C語(yǔ)言的幾道經(jīng)典面試題小結(jié)(分享)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05
C/C++?-?從代碼到可執(zhí)行程序的過(guò)程詳解
這篇文章主要介紹了C/C++?-?從代碼到可執(zhí)行程序的過(guò)程,主要有預(yù)編譯和編譯,匯編鏈接,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-01-01
C語(yǔ)言利用cJSON解析JSON格式全過(guò)程
cJSON是用于解析json格式字符串的一套api,非常好用,下面這篇文章主要給大家介紹了關(guān)于C語(yǔ)言利用cJSON解析JSON格式的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
C語(yǔ)言如何實(shí)現(xiàn)翻轉(zhuǎn)字符串中的單詞
這篇文章主要介紹了C語(yǔ)言如何實(shí)現(xiàn)翻轉(zhuǎn)字符串中的單詞,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
淺談C++對(duì)象的內(nèi)存分布和虛函數(shù)表
下面小編就為大家?guī)?lái)一篇淺談C++對(duì)象的內(nèi)存分布和虛函數(shù)表。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12
C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易停車(chē)場(chǎng)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易停車(chē)場(chǎng)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03

