diff options
Diffstat (limited to 'examples/sql/books/bookdelegate.py')
-rw-r--r-- | examples/sql/books/bookdelegate.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/examples/sql/books/bookdelegate.py b/examples/sql/books/bookdelegate.py index 584203561..78295adf1 100644 --- a/examples/sql/books/bookdelegate.py +++ b/examples/sql/books/bookdelegate.py @@ -13,7 +13,8 @@ class BookDelegate(QSqlRelationalDelegate): def __init__(self, parent=None): QSqlRelationalDelegate.__init__(self, parent) - self.star = QPixmap(":/images/star.png") + self.star = QPixmap(":/images/star.svg") + self.star_filled = QPixmap(":/images/star-filled.svg") def paint(self, painter, option, index): """ Paint the items in the table. @@ -43,19 +44,19 @@ class BookDelegate(QSqlRelationalDelegate): if option.state & QStyle.State_Selected: painter.fillRect(option.rect, - option.palette.color(color_group, QPalette.Highlight)) + option.palette.color(color_group, QPalette.Highlight)) rating = model.data(index, Qt.DisplayRole) width = self.star.width() height = self.star.height() x = option.rect.x() y = option.rect.y() + (option.rect.height() / 2) - (height / 2) - for i in range(rating): - painter.drawPixmap(x, y, self.star) + for i in range(5): + if i < rating: + painter.drawPixmap(x, y, self.star_filled) + else: + painter.drawPixmap(x, y, self.star) x += width - # Since we draw the grid ourselves: - self.drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)) - pen = painter.pen() painter.setPen(option.palette.color(QPalette.Mid)) painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight()) |