[PyQt] QPoint not automatically cast to QPointF

Phil Thompson phil at riverbankcomputing.com
Thu Sep 20 09:49:50 BST 2012


On Thu, 20 Sep 2012 07:34:10 +0530, Shriramana Sharma <samjnaa at gmail.com>
wrote:
> In my recent work with Beziers I ran across this. A QPoint is *not*
> automatically converted into a QPointF in Python/PyQt while it *is*
> converted in C++:
> 
> The following C++ code compiles fine:
> 
> # include <QtCore/QPoint>
> # include <QtGui/QPainterPath>
> int main ( void ) {
> 	QPainterPath p ;
> 	QPoint p1 ( 100, 150 ), c1 ( 166, 250 ), c2 ( 234, 250 ), p2 ( 300, 150
)
> 	;
> 	p . moveTo ( p1 ) ;
> 	p . cubicTo ( c1, c2, p2 ) ;
> }
> 
> whereas its Python/PyQt equivalent:
> 
> #! /usr/bin/env python3
> from PyQt4 . QtCore import QPoint
> from PyQt4 . QtGui import QPainterPath
> p = QPainterPath ()
> p1 = QPoint ( 100, 150 )
> c1 = QPoint ( 166, 250 )
> c2 = QPoint ( 234, 250 )
> p2 = QPoint ( 300, 150 )
> p . moveTo ( p1 )
> p . cubicTo ( c1, c2, p2 )
> 
> produces the following:
> 
> Traceback (most recent call last):
>   File "./qpoint-test.py", line 11, in <module>
>     p . moveTo ( p1 )
> TypeError: arguments did not match any overloaded call:
>   QPainterPath.moveTo(QPointF): argument 1 has unexpected type 'QPoint'
>   QPainterPath.moveTo(float, float): argument 1 has unexpected type
>   'QPoint'
> 
> But QPointF in PyQt *does* provide a constructor from QPoint, so is
> this the limitation of Python that it does not automatically check
> whether it can convert one type to another to satisfy a function's
> call signature? (Or is there some other fault in my PyQt code?)
> 
> I realize I could always convert it manually using QPointF(p1) etc but
> the assumption seems natural that an integer-precision numeric object
> should be accepted where a float-precision can...

It requires a change to SIP to handle this automatically which is on the
TODO list but I haven't got round to it yet.

Phil


More information about the PyQt mailing list