pyqt on python 3.10 - implicit float to int conversion issue

meta 0x0meta at gmail.com
Mon Jun 13 16:56:56 BST 2022


Hello,

When using PyQt with previous versions of Python, a float can be passed
where an int is expected e.g. QColor(0, 0, 0, 255 * some_float).

With 3.10 however, the same code gives the following error:
```
TypeError: arguments did not match any overloaded call:
  QColor(Qt.GlobalColor): argument 1 has unexpected type 'int'
  QColor(int): too many arguments
  QColor(QRgba64): argument 1 has unexpected type 'int'
  QColor(Any): too many arguments
  QColor(): too many arguments
  QColor(int, int, int, alpha: int = 255): argument 4 has unexpected type
'float'
  QColor(str): argument 1 has unexpected type 'int'
  QColor(Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has
unexpected type 'int'
```

Specifically `QColor(int, int, int, alpha: int = 255): argument 4 has
unexpected type 'float'`.

I believe this is related to the following deprecation in 3.8 which was
solidified in 3.10: https://bugs.python.org/issue36048

Cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220614/db8a0319/attachment.htm>


More information about the PyQt mailing list