这篇文章给大家分享的是有关QT实现提示右下角冒泡效果的方法是什么的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
实现原理:
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);
}
}
感谢各位的阅读!关于QT实现提示右下角冒泡效果的方法是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。