[PyQt] Comparison of QPointF

Phil Thompson phil at riverbankcomputing.com
Fri Mar 29 18:10:46 GMT 2013


On Thu, 28 Mar 2013 12:10:37 +0100, Vincent Vande Vyvre
<vincent.vandevyvre at swing.be> wrote:
> Hi,
> 
> I need to check the proximity of two QPointF for implement a snap grid 
> behaviour, but the comparison of the two points is inexact or fail with 
> Python3.
> 
> Platform    Linux-3.2.0-39-generic-x86_64-with-Ubuntu-12.04-precise
> Python        2.7.3
> Qt            4.8.1
> PyQt        4.9.1
> Sip            4.13.2
> 
>  >>> from PyQt4 import QtCore
>  >>> QtCore.QPointF(172.0, 106.0) < QtCore.QPointF(5.0, 5.0)
> True
>  >>> QtCore.QPointF(5.0, 5.0) < QtCore.QPointF(172.0, 106.0)
> False
>  >>> QtCore.QPointF(-5.0, -5.0) < QtCore.QPointF(172.0, 106.0)
> True
>  >>> QtCore.QPointF(5.0, 5.0) < QtCore.QPointF(-172.0, -106.0)
> False
>  >>> QtCore.QPointF(172.0, 106.0) > QtCore.QPointF(5.0, 5.0)
> False
>  >>> QtCore.QPointF(172.0, 106.0) == QtCore.QPointF(172.0, 106.0)
> True
> 
> -------------------------------------------------------------
> Python        3.2.3
> Qt            4.8.1
> PyQt        4.9.1
> Sip            4.13.2
> 
>  >>> from PyQt4 import QtCore
>  >>> QtCore.QPointF(5.0, 5.0) < QtCore.QPointF(172.0, 106.0)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: unorderable types: QPointF() < QPointF()
>  >>> QtCore.QPointF(167.0, 101.0) == QtCore.QPointF(167.0, 101.0)
> True
>  >>> QtCore.QPointF(167.0, 101.0) <= QtCore.QPointF(167.0, 101.0)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: unorderable types: QPointF() <= QPointF()

QPointF doesn't support the comparison you are trying to do. In Python2
this falls back to a (useless) pointer comparison. In Python3 this
(correctly) raises an exception.

Phil


More information about the PyQt mailing list