简体   繁体   English

如何获得对另一个qt小部件功能的访问?

[英]How to get access to another qt widget function?

I am working on a Qt/Python program, which includes one QMainWindow, that also has two widgets (Let's call them Widget A and Widget B). 我正在开发一个Qt / Python程序,其中包括一个QMainWindow,它也有两个小部件(我们称它们为Widget A和Widget B)。

I would like to get some value by running "someFunction()" which is arranged in Widget A from Widget B. So, I tried the following code in the constructor of Widget B: 我想通过运行小部件B中的小部件A中排列的“ someFunction()”来获得一些价值。因此,我在小部件B的构造函数中尝试了以下代码:

self.someValue = self.parent().findChild(WidgetB).someFunction()

But it do not work at all. 但这根本不起作用。 If I run this function in the constructor I do not even get any error or something. 如果我在构造函数中运行此函数,我什至不会得到任何错误或什么。

Could someone explain this behaviour? 有人可以解释这种行为吗? Or better, tell me how to run this function in another widget!? 还是更好,请告诉我如何在另一个小部件中运行此功能!

Thanks in advance! 提前致谢!

I found the solution! 我找到了解决方案!

The problem was, that the parent-widget in the constructor has another parent than the rest of the class... or something like this.. but anyway, here is the code that worked properly: 问题是,构造函数中的parent-widget比该类的其余部分有另一个parent ...或类似的东西..但是无论如何,这是正常工作的代码:

self.parent().parent().findChild(widgets.WidgetA).someFunction()

Hope that I can help anyone who also has this problem! 希望我能帮助还有这个问题的任何人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM