QT day1
作业
代码
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(); //显示对面
}
// 绑定窗口 仅允许两个窗口相互绑定,所以返回值void
void operator==(Widget& other)
{
this->other = &other;
other.other = this;
}
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv); // 创建 QApplication
Widget w1 , w2; //创建界面
w1 == w2; //界面绑定
w1.show();
return app.exec(); // 启动事件循环
}
效果