Qt:day1

一、作业

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

        创建2个Widget对象:

                Widget w1, w2;

                w1.show();

                w2不管;

        要求:

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

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

【代码】:

#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("l消失吧~");
    hbl->addWidget(btn);

    QObject::connect(Widgetl::btn, &QPushButton::clicked, this, &Widgetl::hide);
}

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

    QObject::connect(Widgetr::btn, &QPushButton::clicked, this, &Widgetr::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();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值