# Notification **Repository Path**: chen_xuyuan/notification ## Basic Information - **Project Name**: Notification - **Description**: Qt实现Notification,可自定义4个方向和类型 - **Primary Language**: C++ - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 2 - **Created**: 2022-01-01 - **Last Updated**: 2024-11-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Notification # 介绍 Qt实现的Notification,是一种悬浮在角落的通知提醒。 # 效果预览 ![效果](https://img-blog.csdnimg.cn/83e50ae7715d450dbc2f1be291f00430.gif#pic_center) # 如何使用 ## 创建   Notification的创建必须基于一个QWidget实例,否则会出错。 ```cpp Notification* nf = new Notification(QWidget*); ``` ## 显示   Notification的使用比较简单,只需要调用一个`Push`函数即可,函数原型如下: ```cpp /** * @brief Push 显示提示框 * @param type 提示类型 * @param pos 提示的方向(左上、左下、右上、右下) * @param title 提示的标题 * @param content 提示的内容 * @param nLive 提示框的存活时间,默认3000ms,若该值等于0,提示框不消失。 */ void Push(NotifyType type, NotifyPosition pos, QString title, QString content, int nLive = 3000); ```   要注意的是`NotifyType`和`NotifyPosition`两个参数,它们分别代表了通知的类型和显示的位置。 > ### NotifyType   NotifyType枚举如下: ```cpp /** * @brief The NotifyType enum 消息类型 */ enum NotifyType { Notify_Type_None = 0x30, // 普通 Notify_Type_Success, // 成功 Notify_Type_Error, // 错误 Notify_Type_Warning, // 警告 Notify_Type_Information // 信息 }; ``` > ### NotifyPosition   NotifyPosition枚举如下: ```cpp /** * @brief The NotifyPosition enum 消息位置 */ enum NotifyPosition { Pos_Top_Right = 0x40, // 右上角开始提醒,从上至下 Pos_Top_Left, // 左上角开始提醒,从上至下 Pos_Bottom_Left, // 左下角开始提醒,从下至上 Pos_Bottom_Right // 右下角开始提醒,从下至上 }; ``` ## Demo ```cpp MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { Notification* nf = new Notification(this); QPushButton* btn1 = new QPushButton("Notify", this); connect(btn1, &QPushButton::clicked, this, [&,nf](){ nf->Push(NotifyType::Notify_Type_Success, NotifyPosition::Pos_Top_Left, "Title", "ContentABCD123!@$@#"); }); } ``` ## 其它 - 可以查看`mainwindow.cpp`以及运行项目,来尝试所有风格的通知。 - 由于自己使用,不支持自定义样式,需要的可以自己查看源码修改。