zoukankan      html  css  js  c++  java
  • Qt的主窗口弹出消息框

    先说一下整体思路,其实很简单主要使用到了Qt 的定时器,两个QWidget窗体,消息窗我们只要让它按着定时器的节奏把它向左移动它的宽度或向右移动它的宽度从而实现消息框的弹出与隐藏。

    主要代码:

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    #include "form.h"
    #include <QTimer>
    
    namespace Ui {
        class Widget;
    }
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit Widget(QWidget *parent = 0);
        ~Widget();
    
    private:
        Ui::Widget *ui;
        Form *smallWidget;
        QTimer *timer;
        int progressCount;
        bool backFlag;
    public slots:
        void widgetShow();
        void changeShowflag();
        void makeTimerstart();
    
    };
    
    #endif // WIDGET_H
    #include "widget.h"
    #include "ui_widget.h"
    
    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
        smallWidget = new Form(this);
        smallWidget->setGeometry(640,110,smallWidget->width(),smallWidget->height());
        smallWidget->show();
        timer = new QTimer();
        connect(timer,SIGNAL(timeout()),this,SLOT(widgetShow()));
        progressCount = 740;
        timer->start(10);
        backFlag = false;
        connect(smallWidget,SIGNAL(backFlag()),this,SLOT(changeShowflag()));
        connect(smallWidget,SIGNAL(widgetShow()),this,SLOT(makeTimerstart()));
    }
    void Widget::widgetShow()
    {
        //progressCount=progressCount-25;
        if(!backFlag)
        {
            progressCount--;
            if(progressCount <= 640)
            {
                //progressCount = 740;
                timer->stop();
            }
            smallWidget->setGeometry(progressCount,110,smallWidget->width(),smallWidget->height());
    
        }
        else
        {
            progressCount++;
            if(progressCount == 740)
            {
                backFlag = false;
                timer->stop();
            }
            smallWidget->setGeometry(progressCount,110,smallWidget->width(),smallWidget->height());
    
        }
    
    
    }
    void Widget::changeShowflag()
    {
        this->backFlag = true;
        this->timer->start();
    }
    
    void Widget::makeTimerstart()
    {
        if(progressCount>=640)
        {
            timer->start();
        }
    }
    Widget::~Widget()
    {
        delete ui;
    }

    运行效果:

  • 相关阅读:
    建站两个月,说说我的想法
    我见过的郭弃疾先生(兰亭集势CEO)
    C#数组和集合互相转换的几种方法的效率分析
    (五)React Ant Design Pro + .Net5 WebApi:后端环境搭建Autofac注入+ 泛型仓储
    关于C++中对私有的测试总结
    uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型(转)
    GDB调试
    linux删除乱码文件
    转:C++ nan
    vim
  • 原文地址:https://www.cnblogs.com/onlycxue/p/2755636.html
Copyright © 2011-2022 走看看