将函数分配给 QcomboBox 中的更改 [英] Assign a function to a change in QcomboBox

查看:44
本文介绍了将函数分配给 QcomboBox 中的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 QcomboBox 发生变化时,我尝试调用一个函数.当组合框更改时,它将更新图形上的 xAxis.当从组合框中选择不同的项目时,有没有办法调用函数?

I have tried to call a function when there has been a change in the QcomboBox. When the comboBox is changed it will update the xAxis on a graph. Is there a way to call a function when a different item is selected from the comboBox?

def updateGraph():
    print("update graph")

proxy = QtGui.QGraphicsProxyWidget()
xAxis = QtGui.QComboBox()
proxy.setWidget(xAxis)
xAxis.currentIndexChanged().connect(updateGraph)

当前产生的错误:

TypeError: native Qt signal is not callable

推荐答案

换行

xAxis.currentIndexChanged().connect(updateGraph)

xAxis.currentIndexChanged.connect(updateGraph)

使用currentIndexChanged 前面的括号,您实际上是在调用信号,当您确实想访问信号的connect 方法时.

With the parentheses in front of currentIndexChanged you are actually calling the signal, when you really want to access the signal's connect method.

这篇关于将函数分配给 QcomboBox 中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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