需要来自 QWidget 的类似完成信号的东西 [英] Need something like a finished-signal from QWidget

查看:54
本文介绍了需要来自 QWidget 的类似完成信号的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找类似 QDialog 的完成信号之类的东西,仅用于 QWidget.原因是,一旦小部件弹出,我就禁用了我的工具栏(这根本不是问题),并且我希望在小部件关闭后再次启用工具栏.

I'm searching for something like the finished-signal from QDialog, only for QWidget. The reason is, I disable my toolbar once the widget pops up (which isn't a problem at all) and I want the toolbar to be enabled again, once the widget is closed.

我也不能覆盖那个小部件的关闭事件,因为那样我们就会在业务类中拥有 GUI 代码.

I also can't override the close-Event of that widget, because then we would have GUI-code in business-classes.

推荐答案

你可以设置widget在close时被删除,然后监听它的destroyed信号:

You can set the widget to be deleted on close, and then listen to its destroyed signal:

widget->setAttribute( Qt::WA_DeleteOnClose );
connect( widget, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*)) );

这仅在您对小部件内容不感兴趣时​​才有效.在发出 destroyed() 时,小部件不再是 QWidget,只是一个 QObject(如 destroyed() 是从 ~QObject) 发出的,因此您不能再将参数 QObject* 转换为 QWidget.

That only works if you're not interested in the widget contents though. At the point destroyed() is emitted, the widget isn't a QWidget anymore, just a QObject (as destroyed() is emitted from ~QObject), so you can't cast the argument QObject* to QWidget anymore.

一个简单的替代方法可能是用 QDialog 包装您的小部件.

A simple alternative might be to wrap your widget with a QDialog.

这篇关于需要来自 QWidget 的类似完成信号的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆