捕获 QComboBox 的当前索引
Catching currentindex of a QComboBox
我有一个包含三个元素的弹出列表(QComboBox),我想显示一个toolTip(通过setToolTip 在 QComboBox 上调用)取决于项目的编号。
显示工具提示工作正常,但它是静态的,当用户选择不同于第一个的项目时它不会改变。
想法是每次用户选择一个项目时获取当前项目编号,并将该项目的编号传递给方法algorithms_info
方法algorithms_info的签名是:
def algorithms_info(self, a=0):
所以我设置了一个信号:
self.algoList.connect(self.algoList, QtCore.SIGNAL(_fromUtf8("currentItemChanged(int)")), self.algorithms_info(int))
当我 运行 脚本时,显示以下错误:
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
错误在信号声明中,但如果您有任何关于以其他方式执行此操作的建议,那么我将很高兴。
你只需要self.algoList.currentItemChanged.connect(self.algorithms_info)
。我想在这之后,你会没事的。
您可以在每个项目上设置工具提示,因此不需要信号:
for index in range(10):
combo.setItemData(index, 'Item (%d)' % index, QtCore.Qt.ToolTipRole)
我有一个包含三个元素的弹出列表(QComboBox),我想显示一个toolTip(通过setToolTip 在 QComboBox 上调用)取决于项目的编号。
显示工具提示工作正常,但它是静态的,当用户选择不同于第一个的项目时它不会改变。
想法是每次用户选择一个项目时获取当前项目编号,并将该项目的编号传递给方法algorithms_info
方法algorithms_info的签名是:
def algorithms_info(self, a=0):
所以我设置了一个信号:
self.algoList.connect(self.algoList, QtCore.SIGNAL(_fromUtf8("currentItemChanged(int)")), self.algorithms_info(int))
当我 运行 脚本时,显示以下错误:
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
错误在信号声明中,但如果您有任何关于以其他方式执行此操作的建议,那么我将很高兴。
你只需要self.algoList.currentItemChanged.connect(self.algorithms_info)
。我想在这之后,你会没事的。
您可以在每个项目上设置工具提示,因此不需要信号:
for index in range(10):
combo.setItemData(index, 'Item (%d)' % index, QtCore.Qt.ToolTipRole)