diff options
author | Samuel Gaist <samuel.gaist@idiap.ch> | 2020-01-12 20:15:56 +0100 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@idiap.ch> | 2020-01-27 23:41:08 +0100 |
commit | 1f827cc1cba846eb2c6edacd2096469e4b0bc400 (patch) | |
tree | a229d3168793b9892ace6b816be3c20a2c800ba3 | |
parent | d823a2740d4dabc925f9082f28ac9865188ec8ab (diff) |
examples: improve the star delegate example
While the example works correctly as is, if one takes the StarEditor
class alone, it will fail to work as it uses a starRating attribute that
is available in the example only because of the call to setEditorData
by the StarDelegate class.
This patch fixes that as well makes use of the append overload of
QPolygonF taking a list of point to simplify the code a bit.
Change-Id: Id8132fa86f5668645f48c62377dac65f707c968b
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | examples/widgets/itemviews/stardelegate/stareditor.py | 4 | ||||
-rw-r--r-- | examples/widgets/itemviews/stardelegate/starrating.py | 3 |
2 files changed, 4 insertions, 3 deletions
diff --git a/examples/widgets/itemviews/stardelegate/stareditor.py b/examples/widgets/itemviews/stardelegate/stareditor.py index 5921b73be..820aba8bf 100644 --- a/examples/widgets/itemviews/stardelegate/stareditor.py +++ b/examples/widgets/itemviews/stardelegate/stareditor.py @@ -45,9 +45,10 @@ from PySide2.QtWidgets import (QWidget) from PySide2.QtGui import (QPainter) from PySide2.QtCore import Signal +from starrating import StarRating class StarEditor(QWidget): - """ The custome editor for editing StarRatings. """ + """ The custom editor for editing StarRatings. """ # A signal to tell the delegate when we've finished editing. editingFinished = Signal() @@ -60,6 +61,7 @@ class StarEditor(QWidget): self.setMouseTracking(True) self.setAutoFillBackground(True) + self.starRating = StarRating() def sizeHint(self): """ Tell the caller how big we are. """ diff --git a/examples/widgets/itemviews/stardelegate/starrating.py b/examples/widgets/itemviews/stardelegate/starrating.py index d056e4c64..d40b382f4 100644 --- a/examples/widgets/itemviews/stardelegate/starrating.py +++ b/examples/widgets/itemviews/stardelegate/starrating.py @@ -68,8 +68,7 @@ class StarRating(object): diamondPoints = [QPointF(0.4, 0.5), QPointF(0.5, 0.4), QPointF(0.6, 0.5), QPointF(0.5, 0.6), QPointF(0.4, 0.5)] - for point in diamondPoints: - self.diamondPolygon.append(point) + self.diamondPolygon.append(diamondPoints) def sizeHint(self): """ Tell the caller how big we are. """ |