将 python 函数作为信号直接应用到 Qt 设计器
总的来说,我对 Qt 和 GUI 编程很陌生,但我已经用 python 编写了相当多的代码 - 编写模块等等。我需要为我的一些旧模块开发简单的 GUI。
我想要做的事情可以用下面的简单示例来表示:
def f(x, y):
z = x + y
return z
对于这个函数,我将为 x 和 y 提供两行编辑,为 z 提供一行编辑。现在我创建一个按钮“计算”,当我这样做时,我希望它从行编辑中获取 x 和 y 运行函数 f(x,y)
并将输出提供给 z 。
有没有办法通过添加用 python 编写的函数 f(x,y)
直接在 Qt Designer 中执行此操作?
如果不是,还有什么替代方案?
I am new to Qt and GUI programming overall but i have done a fair bit of coding in python - writing modules and so on. I need to develop simple GUIs for some of my old modules.
What i am trying to do can be represented by the following simple example:
def f(x, y):
z = x + y
return z
For this function i will give two line-edits for x and y and one for z. Now i create a push-button 'calculate' and when i do that i want it to take x and y from the line-edits run the function f(x,y)
and give the output to z.
Is there any way to do this directly in Qt Designer by adding the function f(x,y)
written in python?
If not what are the alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写 PyQt4 gui 时的基本工作流程是:
因此,给定 UI 文件
calc.ui
,您可以使用以下方式生成 UI 模块:然后创建一个如下所示的应用程序模块:
请注意,它有助于设置
objectName
对于 Designer 的属性编辑器中的每个小部件,以便以后可以轻松识别它们。特别是,主窗体的objectName
将成为导入的 GUI 类的类名(假设使用了pyuic4
的“-w”标志)。The basic workflow when writing a PyQt4 gui is:
pyuic4
.So, given the UI file
calc.ui
, you could generate the UI module with:And then create an application module something like this:
Note that it helps to set the
objectName
for every widget in Designer's Property Editor so that they can be easily identified later on. In particular, theobjectName
of the main form will become class-name of the GUI class that is imported (assuming the "-w" flag topyuic4
is used).