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();
}
相关推荐
CoderCodingNo9 分钟前
【GESP】C++六级考试大纲知识点梳理, (7) 栈与队列
开发语言·c++
超级大福宝16 分钟前
【力扣200. 岛屿数量】的一种错误解法(BFS)
数据结构·c++·算法·leetcode·广度优先
Frank_refuel1 小时前
C++之继承
开发语言·c++
哪有时间简史2 小时前
C++程序设计
c++
%xiao Q2 小时前
GESP C++四级-216
java·开发语言·c++
tianyuanwo2 小时前
深入浅出SWIG:从C/C++到Python的无缝桥梁
c语言·c++·python·swig
初次见面我叫泰隆3 小时前
Qt——2、信号和槽
开发语言·c++·qt
D_evil__3 小时前
【Effective Modern C++】第二章 auto:5. 优先使用 auto,而非显式类型声明
c++
玖釉-3 小时前
[Vulkan 学习之路] 26 - 图像视图与采样器 (Image View and Sampler)
c++·windows·图形渲染
一颗青果3 小时前
C++的锁 | RAII管理锁 | 死锁避免
java·开发语言·c++