当前位置: 首页 > article >正文

QT-对象树

思维导图

写1个Widget窗口,窗口里面放1个按钮,按钮随便叫什么 创建2个Widget对象 Widget w1,w2 w1.show() w2不管 要求:点击 w1.btn ,w1隐藏,w2显示 点击 w2.btn ,w2隐藏,w1 显示

#include <QApplication>
#include <QDebug>
#include <QLabel>
#include <QPalette>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLayout>
#include <QWidget>
#include <QTextEdit>
using namespace std;

class Widget:public QWidget{

    QPushButton* btn;
    Widget* other;

public:
    Widget()
        :btn(NULL),other(NULL)
    {
        btn = new QPushButton(this);
        btn->setText("按钮");
        QObject::connect(btn,&QPushButton::clicked,this,&Widget::Event);

    }

    void Event()
    {
        this->hide();
        other->show();
    }

    void operator==(Widget& other)
    {
        this->other=&other;
        other.other=this;
    }
};
int main(int argc,char** argv)
{
    QApplication app(argc,argv);//QT应用程序的入口类
    Widget w1,w2;
    w1==w2;
    w1.show();
    return app.exec();
}


http://www.kler.cn/a/568828.html

相关文章:

  • Linux基础开发工具——vim(5)
  • 带你深入了解前端【HTML+JavaScript】
  • web3.0简介
  • Jenkinsfile流水线构建教程
  • Vulhub靶机 AppWeb认证绕过漏洞(CVE-2018-8715)(渗透测试详解)
  • jenkens使用笔记
  • 【手撕算法】K-Means聚类全解析:从数学推导到图像分割实战
  • 解决单元测试 mock final类报错
  • 深入理解Web通信基础:HTTP响应码、请求方法与协议安全
  • Qt | 实战继承自QObject的IOThread子类实现TCP客户端(安全销毁)
  • Codeforces Round 1007 (Div. 2)(ABCD1)
  • 代码的解读——自用
  • 如何把网络ip改为动态:全面指南
  • 当JMeter遇见AI:性能测试进入智能时代(附实战案例)
  • 链表OJ(十二)23. 合并 K 个升序链表 困难 优先级队列中存放指针结点
  • 计算器算法题
  • Maven 与持续集成(CI)/ 持续部署(CD)(二)
  • EasyRTC:支持任意平台设备的嵌入式WebRTC实时音视频通信SDK解决方案
  • 前端正则表达式完全指南:从入门到实战
  • (贪心 合并区间)leetcode 56