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();
}
相关推荐
雾岛听蓝1 小时前
C++:模拟实现string类
开发语言·c++
XFF不秃头1 小时前
力扣刷题笔记-合并区间
c++·笔记·算法·leetcode
编程之路,妙趣横生1 小时前
STL(七) unordered_set 与 unordered_map 基本用法 + 模拟实现
c++
寂柒1 小时前
c++--
c++
wregjru2 小时前
【读书笔记】Effective C++ 条款3:尽可能使用const
开发语言·c++
历程里程碑3 小时前
滑动窗口秒解LeetCode字母异位词
java·c语言·开发语言·数据结构·c++·算法·leetcode
Tandy12356_3 小时前
手写TCP/IP协议栈——TCP结构定义与基本接口实现
c语言·网络·c++·网络协议·tcp/ip·计算机网络
Helibo443 小时前
2025年12月gesp3级题解
数据结构·c++·算法
西幻凌云3 小时前
初始——正则表达式
c++·正则表达式·1024程序员节
沧澜sincerely4 小时前
蓝桥杯101 拉马车
c++·蓝桥杯·stl