作业
代码
class Widget: public QWidget
{QPushButton* button; //按钮Widget* other; //显示对面
public:Widget(){button = new QPushButton("按钮",this); //控件 认this作父this->resize(300,300); //界面大小button->resize(100,100); //按钮大小QObject::connect(button,&QPushButton::clicked,this,&Widget::Clicked_Event);}// 按钮点击事件void Clicked_Event(){this->hide(); //隐藏自己other->show(); //显示对面}// 绑定窗口 仅允许两个窗口相互绑定,所以返回值voidvoid operator==(Widget& other){this->other = &other;other.other = this;}
};int main(int argc, char *argv[]) {QApplication app(argc, argv); // 创建 QApplicationWidget w1 , w2; //创建界面w1 == w2; //界面绑定w1.show();return app.exec(); // 启动事件循环
}
效果