[PyQt] Request for __lshift__ support in QPolygonF for QPointF
Phil Thompson
phil at riverbankcomputing.com
Tue Oct 19 18:25:00 BST 2010
On Tue, 19 Oct 2010 01:18:46 +0200, "Hans-Peter Jansen" <hpj at urpla.net>
wrote:
> Hi Phil,
>
> any deeper reason, why code like this is not supported:
Laziness on my part.
> import math
> from PyQt4 import QtCore, QtGui
>
> class StarRating(object):
> # enum EditMode
> Editable, ReadOnly = range(2)
> PaintingScaleFactor = 20
>
> def __init__(self, starCount, maxStarCount = 5):
> self._starCount = starCount
> self._maxStarCount = maxStarCount
> self.starPolygon = QtGui.QPolygonF()
> self.starPolygon << QtCore.QPointF(1.0, 0.5)
> for i in range(5):
> self.starPolygon << QtCore.QPointF(0.5 + 0.5 * math.cos(0.8
*
> i * 3.14),
> 0.5 + 0.5 * math.sin(0.8
*
> i * 3.14))
> self.diamondPolygon = QtGui.QPolygonF()
> self.diamondPolygon << QtCore.QPointF(0.4, 0.5) \
> << QtCore.QPointF(0.5, 0.4) \
> << QtCore.QPointF(0.6, 0.5) \
> << QtCore.QPointF(0.5, 0.6) \
> << QtCore.QPointF(0.4, 0.5)
>
> This would bring us on a level playing field with C++.
>
> Here's, what has to be done right now:
>
> import math
> from PyQt4 import QtCore, QtGui
>
> class StarRating(object):
> # enum EditMode
> Editable, ReadOnly = range(2)
> PaintingScaleFactor = 20
>
> def __init__(self, starCount, maxStarCount = 5):
> self._starCount = starCount
> self._maxStarCount = maxStarCount
> self.starPolygon = QtGui.QPolygonF([QtCore.QPointF(1.0, 0.5)])
> for i in range(5):
> self.starPolygon.append(
> QtCore.QPointF(0.5 + 0.5 * math.cos(0.8 * i * 3.14),
> 0.5 + 0.5 * math.sin(0.8 * i * 3.14))
> )
>
> self.diamondPolygon = QtGui.QPolygonF([
> QtCore.QPointF(0.4, 0.5), QtCore.QPointF(0.5, 0.4),
> QtCore.QPointF(0.6, 0.5), QtCore.QPointF(0.5, 0.6),
> QtCore.QPointF(0.4, 0.5)
> ])
>
> Given, that this list has to be a list, while a tuple is not accepted,
> doesn't improve the situation, either..
>
> As a bonus, it is expectable, that the former code executes marginally
> quicker.
It will be in tonight's snapshot.
Phil
More information about the PyQt
mailing list