PyQt6: QComboBox.findData does not work for 'python' objects

Ales Erjavec ales.erjavec324 at gmail.com
Mon Jan 31 11:08:01 GMT 2022


Hi,

QComboBox.findData does not work for non mapped data types, i.e:

```
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QComboBox

DataRole = Qt.ItemDataRole.UserRole

A = object()
B = object()

app = QApplication([])

cb = QComboBox()
cb.addItem("A")
cb.addItem("B")
cb.setItemData(0, A, DataRole)
cb.setItemData(1, B, DataRole)
idx = cb.findData(B, DataRole)
assert idx == 1, f"{idx} == 1"
```
fails the assertion test (idx=-1). It does seem to work for int, str, and other
mapped types.

The same code used to work in PyQt5.

OS: Linux
Python: 3.10.1
PyQt6: 6.2.2


More information about the PyQt mailing list