QT-如何通过按下按钮从子窗口小部件返回到父窗口小部件
QT - how to go back from child widget to parent with button press
如何在按下PushButton的情况下从子窗口小部件视图返回到父窗口小部件?
Parent.cpp的一部分,带有子部件初始化:
void Menu::on_pushButton_phone_numbers_clicked()
{
Child child_window(this);
child_window.setModal(true);
child_window.exec(); //child_window.show() only pops out and close program
this->hide();
}
Child.cpp的一部分,我试图回到Parent Widget:
void Child::on_pushButton_parent_clicked()
{
parentWidget()->setHidden(false); // also tried with parentWidget().show()
this->close(); //that results with closing whole program
}
我应该考虑在Parent.cpp中使用connect((吗?还是我应该走另一条路?
或者有没有任何文档可以让我找到如何正确操作的答案?
编辑:主要问题是当调用parent.hide((时-即使动态分配Child-每次尝试隐藏或关闭子窗口小部件时都会引发n_pushButton_pparent_clickd((,这将导致父窗口弹出并关闭整个程序
我会做一些类似的事情
void Menu::on_pushButton_phone_numbers_clicked()
{
Child child_window(this);
connect(child_window, &Child::sig_show, this, [this]{this->show();});
child_window.setModal(true);
child_window.exec();
this->hide();
}
void Child::on_pushButton_parent_clicked()
{
emit sig_show();
this->close();
}
我还没有测试过,但这是我会使用的逻辑。
相关文章:
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 超轻 - 如何最小化窗口
- Gtkmm 窗口为空白,不显示任何小部件或标题
- CreateWindowW 窗口太小
- QT-如何通过按下按钮从子窗口小部件返回到父窗口小部件
- 如何将QEvents传递给子窗口小部件
- 如何隐藏最大化和最小化按钮并在qml应用程序窗口中显示关闭按钮?
- 如何使用 stl 最小化 c++ 中所有打开的窗口
- 是否可以强迫窗口匹配小部件的大小
- 一个人如何将QT(C )UI分为多个小部件子类,并使其显示与同一类中的所有窗口
- 当模式窗口最小化时,最小化所有应用程序窗口(在 Linux 上)
- gtkmm - 如何使包含小部件的框展开以填充窗口
- 替代QDockWidget的小部件,而没有删除以前的窗口
- 什么是窗口最大化/最小化/恢复的WM Windows消息
- 是否可以从其他线程隐藏qt小部件窗口
- 在小尺寸窗口中保存大尺寸图片
- C++ 创建小部件数组
- 如何在C++中将密钥发送到最小化窗口
- 我如何接收或能够在我的小部件窗口外处理mouseMoveEvent(s)
- 从另一个线程最大化/最小化窗口