QT-对象树
思维导图
写1个Widget窗口,窗口里面放1个按钮,按钮随便叫什么 创建2个Widget对象 Widget w1,w2 w1.show() w2不管 要求:点击 w1.btn ,w1隐藏,w2显示 点击 w2.btn ,w2隐藏,w1 显示
#include <QApplication>
#include <QDebug>
#include <QLabel>
#include <QPalette>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLayout>
#include <QWidget>
#include <QTextEdit>
using namespace std;
class Widget:public QWidget{
QPushButton* btn;
Widget* other;
public:
Widget()
:btn(NULL),other(NULL)
{
btn = new QPushButton(this);
btn->setText("按钮");
QObject::connect(btn,&QPushButton::clicked,this,&Widget::Event);
}
void Event()
{
this->hide();
other->show();
}
void operator==(Widget& other)
{
this->other=&other;
other.other=this;
}
};
int main(int argc,char** argv)
{
QApplication app(argc,argv);//QT应用程序的入口类
Widget w1,w2;
w1==w2;
w1.show();
return app.exec();
}