[PyQt] Floats accepted for C++ ints?

Hans-Peter Jansen hpj at urpla.net
Tue Jul 5 18:45:30 BST 2016


On Dienstag, 5. Juli 2016 19:22:14 Florian Bruhin wrote:
> I've noticed Python floats are accepted when a C++ int is expected,
> 
> and simply truncated:
> 	>>> from PyQt5.QtCore import QRect
> 	>>> QRect(0.5, 0.5, 0.5, 0.5)
> 
> 	PyQt5.QtCore.QRect()
> 
> 	>>> QRect(1.5, 1.5, 1.5, 1.5)
> 
> 	PyQt5.QtCore.QRect(1, 1, 1, 1)
> 
> Is this intended behaviour? I'd have expected to raise a TypeError
> (or, if anything, accept floats where .is_integer() is true)

Hmm, you're right, but this behavior is due to historical reasons, and goes 
back to times without a QRectF class.

The QRect(0.5, 0.5, 0.5, 0.5) result looks wrong, though.

Pete


More information about the PyQt mailing list