本文实例为大家分享了QT实现提示右下角冒泡的具体代码,供大家参考,具体内容如下
实现原理:
1、显示
定时器启动,右下角缓慢弹出,逐渐改变位置。
2、驻留
让界面停留一定的时间,时间过后自动关闭。
3、退出
可以直接点击关闭退出,也可以采用改变透明度的形式模糊退出。
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#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
|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#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);
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/swartz_lubel/article/details/54849516








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。