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();
}
相关推荐
我是李武涯21 小时前
从`std::mutex`到`std::lock_guard`与`std::unique_lock`的演进之路
开发语言·c++
卡提西亚21 小时前
C++笔记-10-循环语句
c++·笔记·算法
亮剑20181 天前
第1节:C语言初体验——环境、结构与基本数据类型
c++
William_wL_1 天前
【C++】类和对象(下)
c++
William_wL_1 天前
【C++】内存管理
c++
星星火柴9361 天前
笔记 | C++面向对象高级开发
开发语言·c++·笔记·学习
悲伤小伞1 天前
Linux_Socket_UDP
linux·服务器·网络·c++·网络协议·udp
八个程序员1 天前
自定义函数(C++)
开发语言·c++·算法
微露清风1 天前
系统性学习C++-第十讲-stack 和 quene
java·c++·学习
报错小能手1 天前
C++笔记(面向对象)静态联编和动态联编
开发语言·c++·算法