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();
}
相关推荐
刃神太酷啦39 分钟前
C++(蓝桥杯常考点)
数据结构·c++·蓝桥杯c++组
Lenyiin2 小时前
第151场双周赛:将数组按照奇偶性转化、可行数组的数目、移除所有数组元素的最小代价、全排列 Ⅳ
c++·算法·leetcode·周赛·lenyiin
Ace'3 小时前
每日一题之R格式
c++·算法
The_era_achievs_hero3 小时前
c++上课题目
数据结构·c++·算法
EutoCool3 小时前
Linux:同步
linux·服务器·c++
Maryhuan3 小时前
【开源-常用C/C++命令行解析库对比】
c语言·开发语言·c++
进击的_鹏3 小时前
【C++】stack和queue以及priority_queue的使用以及模拟实现
开发语言·c++·算法
闻缺陷则喜何志丹3 小时前
【二分查找 前缀和】P10429 [蓝桥杯 2024 省 B] 拔河|普及+
c++·算法·前缀和·蓝桥杯·二分查找·洛谷·拔河
New_Teen5 小时前
C++小课堂——变量的声明,赋值和初始化
开发语言·c++·笔记·学习
努力努力再努力wz5 小时前
【Linux实践系列】:用c语言实现一个shell外壳程序
linux·运维·服务器·c语言·c++·redis