需要来自 QWidget 的完成信号之类的东西
我正在寻找来自 QDialog
的完成信号之类的东西,仅适用于 QWidget
。原因是,一旦小部件弹出(这根本不是问题),我就禁用工具栏,并且我希望在小部件关闭后再次启用工具栏。
我也无法覆盖该小部件的 close-Event,因为那样我们就会在业务类中拥有 GUI 代码。
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.
I also can't override the close-Event of that widget, because then we would have GUI-code in business-classes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将小部件设置为在关闭时删除,然后监听其
destroyed
信号:不过,只有当您对小部件内容不感兴趣时,这才有效。在发出
destroyed()
时,小部件不再是QWidget
,而只是一个QObject
(如destroyed()
是从~QObject
发出的),因此您无法再将参数QObject*
转换为QWidget
。一个简单的替代方案可能是用
QDialog
包装您的小部件。You can set the widget to be deleted on close, and then listen to its
destroyed
signal:That only works if you're not interested in the widget contents though. At the point
destroyed()
is emitted, the widget isn't aQWidget
anymore, just aQObject
(asdestroyed()
is emitted from~QObject
), so you can't cast the argumentQObject*
toQWidget
anymore.A simple alternative might be to wrap your widget with a
QDialog
.在您的 Widget 类中,您可以添加其他人可以连接到的自己的信号。然后重写
closeEvent()
方法。不用担心重写这个方法,这种情况正是这样做的正确理由。在
closeEvent
方法中触发您的信号:In your Widget class, you can add your own signal that others can connect to. Then override the
closeEvent()
method. Don't worry about overriding this method, this kind of situation is exactly the right reason do to it.In the
closeEvent
method trigger your signal:QWidget 实际上没有很多信号,根据文档,它总共有 2 个。但是,这并不意味着您不能自己指定信号并使用它,这可能是最好的方法。
QWidget doesn't have many signals really, according to the documentation it has a grand total of 2. However, that doesn't mean you can't specify a signal yourself and use it, which is probably the best method.