Qt:day1

一、作业

写1个Widget窗口,窗口里面放1个按钮,按钮随便叫什么;

创建2个Widget对象:

Widget w1, w2;

w1.show();

w2不管;

要求:

点击 w1.btn,w1隐藏,w2显示;

点击 w2.btn,w2隐藏,w1显示。

【代码】:

cpp 复制代码
#include <QApplication>
#include <QDebug>
#include <QHBoxLayout>
#include <QPushButton>
#include <QWidget>

class Widgetl:public QWidget{
    QPushButton* btn;
    QHBoxLayout* hbl;
public:
    Widgetl();
    ~Widgetl();
};

class Widgetr:public QWidget{
    QPushButton* btn;
    QHBoxLayout* hbl;
public:
    Widgetr();
    ~Widgetr();
};

Widgetl::Widgetl()
{
    btn = new QPushButton(this);
    hbl = new QHBoxLayout(this);
    btn->setText("让对方R消失吧~");
    hbl->addWidget(btn);

    //QObject::connect(Widgetl::btn, &QPushButton::clicked, QWidget::Widgetr, &QWidget::hide);
}

Widgetr::Widgetr()
{
    btn = new QPushButton(this);
    hbl = new QHBoxLayout(this);
    btn->setText("让对方L消失吧~");
    hbl->addWidget(btn);

    //QObject::connect(Widgetr::btn, &QPushButton::clicked, QWidget::Widgetl, &QWidget::hide);
}

Widgetl::~Widgetl(){}
Widgetr::~Widgetr(){}

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    Widgetl w1;
    w1.setGeometry(1400, 600, 500, 500);
    w1.show();

    Widgetr w2;
    w2.setGeometry(2100,600, 500, 500);
    w2.show();
    return app.exec();
}
相关推荐
Mr_WangAndy15 分钟前
C++_chapter15_C++重要知识点_lambda,initializer_list
c++·lambda·初始化列表
Maple_land21 分钟前
第1篇:Linux工具复盘上篇:yum与vim
linux·运维·服务器·c++·centos
hggngx548h1 小时前
有哪些C++20特性可以在Dev-C++中使用?
开发语言·c++·c++20
计科土狗2 小时前
算法基础入门第一章
c++·算法
9ilk2 小时前
【仿RabbitMQ的发布订阅式消息队列】 ---- 功能测试联调
linux·服务器·c++·分布式·学习·rabbitmq
北冥湖畔的燕雀2 小时前
std之list
数据结构·c++·list
Elias不吃糖3 小时前
eventfd 初认识Reactor/多线程服务器的关键唤醒机制
linux·服务器·c++·学习
南方的狮子先生3 小时前
【C++】C++文件读写
java·开发语言·数据结构·c++·算法·1024程序员节
玖剹4 小时前
二叉树递归题目(一)
c语言·c++·算法·leetcode
mjhcsp4 小时前
C++ 数组:基础与进阶全解析
开发语言·c++