介绍

基于 QDialog 绘制的信息框,提供一个简单的信息显示,并带有一些动画,默认自动渐隐消失。背景色,字体色可设置,支持渐变色。

使用

  1. #include "VMessageBox.h"

基本方法

  1. // 根据parent 坐标 弹出信息框
  2. //static void information(QWidget *parent, const QString &msg, int timeout = 2000, QString bgColor = 0, QString fontColor = 0);
  3. // 根据提供的坐标 弹出信息框
  4. static void information(const QPoint &point, const QString &msg, int timeout = 2000, QString bgColor = 0, QString fontColor = 0);
  5. // 根据内置提供的坐标 弹出信息框
  6. static void information(QWidget *parent, const QString &msg, const DefaultPoint &pointType = Center_Bottom, int timeout = 2000, const QString &bgColor = 0, const QString &fontColor = 0);
  7. enum DefaultColor{ Gradient_Blue,Gradient_Red, Gradient_Green}; //内设颜色 不定时的会增加一些
  8. enum DefaultPoint{ Center_Up, Center_Bottom }; //内置坐标
  9. static QString getDefaultColor(DefaultColor colorIndex); //获得内设颜色
  10. //自动判断颜色 parent
  11. static void show(QWidget *parent, const QString &msg,
  12. const QVariant &bgColor = QVariant(), int timeout = 2000, const DefaultPoint &pointType = Center_Bottom, const QString &fontColor = 0);
  13. //自动判断颜色 坐标
  14. static void show(QPoint point, const QString &msg,
  15. const QVariant &bgColor = QVariant(), int timeout = 2000, const QString &fontColor = 0);

实例:

  1. VMessageBox::information(this, "我是一个信息框"); //简单调用 位置居中
  2. VMessageBox::information(QPoint(500,500), "我是一个信息框"); //简单调用 指定坐标弹出
  3. VMessageBox::information(this, "我是一个信息框", 3000); //指定信息框存在时间
  4. VMessageBox::information(this, "我是一个信息框", 3000, "red"); //设置背景色
  5. VMessageBox::information(this, "我是一个信息框", 3000, "red", "pink"); //设置背景色和字体色
  6. VMessageBox::information(this, "我是一个信息框", 3000, "#fff", "#000"); //设置背景色和字体色
  7. VMessageBox::information(this, "我是一个信息框", 3000,
  8. VMessageBox::getDefaultColor(VMessageBox::Gradient_Blue), "pink"); //使用内置渐变色
  9. VMessageBox::show(this, "使用渐变色", ".........");
  10. VMessageBox::show(this, "使用色值", "#FFF");
  11. VMessageBox::show(this, "使用内置渐变色", VMessageBox::Gradient_Green);

VMessageBox.gif

实际项目展示:
实例.gif

内置颜色展示
Gradient_Blue 渐变蓝
blue.gif
Gradient_Red 渐变红
red.gif
Gradient_Red 渐变绿
演示.gif**