Python QCombobox finData方法始终使用numpy数组返回-1

Python QCombobox finData方法始终使用numpy数组返回-1,python,python-3.x,numpy,pyside2,qcombobox,Python,Python 3.x,Numpy,Pyside2,Qcombobox,当使用numpy数组添加项时,我在尝试获取组合框上某些数据的索引时遇到问题,而如果使用列表,则结果是预期的 from PySide2 import QtWidgets import numpy as np app = QtWidgets.QApplication() heights_list = [0.52, 1, 2, 3, 4, 12.57, 14.97] heights_array = np.array([0.52, 1, 2, 3, 4, 12.57, 14.97]) comb

当使用numpy数组添加项时,我在尝试获取组合框上某些数据的索引时遇到问题,而如果使用列表,则结果是预期的

from PySide2 import QtWidgets
import numpy as np


app = QtWidgets.QApplication()

heights_list = [0.52, 1, 2, 3, 4, 12.57, 14.97] 
heights_array = np.array([0.52, 1, 2, 3, 4, 12.57, 14.97])

combo_list = QtWidgets.QComboBox()
for height in heights_list:
    combo_list.addItem(f"{height:.2f} m", height)

combo_array = QtWidgets.QComboBox()
for height in heights_array:
    combo_array.addItem(f"{height:.2f} m", height)

print(combo_list.findData(14.97))  # Print 6
print(combo_array.findData(14.97)) # Print -1

该方法使用模型的方法,匹配方法使用s进行比较。PySide2(也是PyQt5)为了具有兼容性,会将(C/C++中python对象的表示形式)转换为int、float等基本类型。但它不知道如何转换numpy对象,然后只存储指针,在比较存储指针的指针时,会比较内存地址,但是作为两个不同的对象,它总是返回它们不是同一个对象。

最后,我使用numpy array
tolist
方法,并从列表中填充组合框。