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(); // 启动事件循环
}
效果
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.dtcms.com/a/42675.html
如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!