重载的pyside信号(QComboBox)

use*_*366 5 signals overloading qcombobox pyside

使用带pyside的QComboBox,我知道如何连接信号并使用它发送的索引.但是unicode论点怎么样?如果我更喜欢连接到需要组合框中的字符串的东西,那可能吗?

来自:http: //www.pyside.org/docs/pyside/PySide/QtGui/QComboBox.html#PySide.QtGui.QComboBox

所有三个信号都存在两个版本,一个带有PySide.QtCore.QString参数,另一个带有int参数.

信号

def activated (arg__1)
def activated (index)
Run Code Online (Sandbox Code Playgroud)

PySide.QtGui.QComboBox.activated(index)参数:index - PySide.QtCore.int

PySide.QtGui.QComboBox.activated(arg_ 1)参数:arg _1 - unicode

编辑:一些代码.

le = ComboBoxIpPrefix()
le.currentIndexChanged.connect(lambda x....)
Run Code Online (Sandbox Code Playgroud)

这段代码给了我索引.问题是如何获取文档中提到的unicode字符串.

Ole*_*pin 12

我不明白你的问题到底是什么.

有两个版本的QComboBox.activated信号.一个为您提供所选项目的索引,另一个为您提供文本.

要在PySide中进行选择,请执行以下操作:

a_combo_box.activated[int].connect(some_callable)

a_combo_box.activated[str].connect(other_callable)
Run Code Online (Sandbox Code Playgroud)

第二行可能不会在Python 2中以这种方式工作,所以strunicode.替换.

请注意,我使用通用(C++)Qt文档,因为PySide文档仍然非常模糊:我一直看到那些arg__1无处不在......
"翻译"到Python应该不会太难.只要记住,QString成为str(或unicode在Python 2;顺便说一下,我喜欢有关于Python的所有版本我的代码的工作,所以我通常做一个别名类型textstr在PY3和unicode中的Py2); long,short等成为int; double变得float; QVariant完全避免,它只是意味着任何数据类型都可以在那里传递; 等等...