[PyQt] Floats accepted for C++ ints?

Florian Bruhin me at the-compiler.org
Tue Jul 5 20:05:32 BST 2016


* Hans-Peter Jansen <hpj at urpla.net> [2016-07-05 19:45:30 +0200]:
> 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.

I don't follow - doing the same in C++ does not work (as expected),
and this is not tied to QRect. Someone in the #pyqt IRC channel
discovered it with QBoxLayout::addStretch originally.

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

It gets rounded down to 0, and QRect(0, 0, 0, 0) is invalid.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160705/44e53518/attachment.sig>


More information about the PyQt mailing list