• qt窗口的切换


    思想:在一个窗口类中声明另一继承与Qdialog的类的变量 还有在另一类中parentwidget()函数获取父类窗口,然后将其隐藏。。

    窗口1:

    mywin1.h

    #ifndef MYWIN1_H
    #define MYWIN1_H
    
    #include <QMainWindow>
    #include"mywin2.h"
    
    namespace Ui {
    class myWin1;
    }
    
    class myWin1 : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit myWin1(QWidget *parent = 0);
        ~myWin1();
    
    private slots:
        void on_pushButton_2_clicked();
    
    private:
        Ui::myWin1 *ui;
        myWin2 *mywind;
    };
    
    #endif // MYWIN1_H

    mywin1.cpp

    #include "mywin1.h"
    #include "ui_mywin1.h"
    #include<mywin2.h>
    
    myWin1::myWin1(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::myWin1)
    {
        ui->setupUi(this);
    
    
    }
    
    myWin1::~myWin1()
    {
        delete ui;
    }
    
    void myWin1::on_pushButton_2_clicked()
    {
          mywind = new myWin2();
          mywind->show();
          this->hide();
    }

    mywin2.h

    #ifndef MYWIN2_H
    #define MYWIN2_H
    
    #include <QMainWindow>
    #include"mywin1.h"
    
    namespace Ui {
    class myWin2;
    }
    
    class myWin2 : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit myWin2(QWidget *parent = 0);
        ~myWin2();
    
    private slots:
        void on_pushButton_clicked();
    
    private:
        Ui::myWin2 *ui;
        myWin1 *mywind1;
    };
    
    #endif // MYWIN2_H

    mywin2.cpp

    #include "mywin2.h"
    #include "ui_mywin2.h"
    #include"mywin1.h"
    
    myWin2::myWin2(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::myWin2)
    {
        ui->setupUi(this);
    }
    
    myWin2::~myWin2()
    {
        delete ui;
    }
    
    void myWin2::on_pushButton_clicked()
    {
    mywind1 = new myWin1();
    mywind1->parentWidget()->show();
    delete this;
    
    }
  • 相关阅读:
    转 :table的边框属性设置总结
    Redis Sentinel 配置文件
    nginx unit的初探
    负载均衡器之 Haproxy
    利用python itchat给女朋友定时发信息
    nginx unit 的使用
    Redis Sentinel 模拟故障迁移
    Python 获取车票信息
    Nginx unit 源码安装初体验
    初识 Proxysql
  • 原文地址:https://www.cnblogs.com/defen/p/5344250.html
Copyright © 2020-2023  润新知