欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > Qt:day1

Qt:day1

2025/3/1 15:01:38 来源:https://blog.csdn.net/longspython/article/details/145937468  浏览:    关键词: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("让对方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();
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词