解决与 PyQt 新式信号槽的冲突 [英] Resolving conflicts with PyQt new-style signals-slots

查看:36
本文介绍了解决与 PyQt 新式信号槽的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QComboBox 有两个信号,都称为 currentIndexChanged;一个传递所选项目的索引,另一个传递所选项目的文本.当我将此信号连接到我的插槽时,使用诸如 self.myComboBox.currentIndexChanged.connect(self.mySlot) 之类的东西,它会给我一个索引.有没有办法可以使用新样式的信号来指示我希望返回文本?

QComboBox has two signals, both called currentIndexChanged; one passes the index of the selected item, and the other passes the text of the selected item. When I connect this signal to my slot, with something like self.myComboBox.currentIndexChanged.connect(self.mySlot) it gives me an index. Is there a way I can use new-style signals to indicate that I want the text returned?

推荐答案

参见 连接信号部分 文档.

在你的情况下是:

self.myComboBox.currentIndexChanged[QtCore.QString].connect(self.mySlot)

或者如果您使用的是 QString

self.myComboBox.currentIndexChanged[str].connect(self.mySlot)

这篇关于解决与 PyQt 新式信号槽的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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