qfedu-basic-level/day11/switchab/awidget.cpp

43 lines
1.0 KiB
C++
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "awidget.h"
aWidget::aWidget(QWidget *parent)
: QWidget(parent)
{
// 设置A窗口实例的属性
setFixedSize(400,200);
setWindowTitle("A界面");
move(200,100);
// 新建B窗口对象
b = new bWidget();
b->setFixedSize(400,200);
b->setWindowTitle("B界面");
b->move(800,100);
// 新建“进入B”按钮并设置其属性
btnToB = new QPushButton("进入B",this);
btnToB->resize(60,40);
// 绑定“进入B”按钮点击信号与“进入B界面并隐藏A界面”的槽函数
connect(btnToB,&QPushButton::clicked,this,&aWidget::toBHandle);
// 绑定“B界面返回A界面信号”与当前界面的“A界面显示并隐藏B界面”的槽函数
connect(b,&bWidget::returnASignal,this,&aWidget::returnAHandle);
}
void aWidget::toBHandle()
{
this->hide(); // 隐藏A界面
b->show(); // 显示B界面
}
void aWidget::returnAHandle()
{
b->hide(); // 隐藏B界面
this->show(); // 显示A界面
}
aWidget::~aWidget()
{
}