Mercurial > hg > tilerswift
changeset 82:c93a436e6dec
color: new palette_to_pixmap function
I plan to draw these little pixmaps in a drop-down button so people
can choose from a few standard palettes.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 10 Sep 2019 13:24:13 -0400 |
parents | 9922cde5ad6c |
children | 68497ba0c711 |
files | colors.py |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/colors.py +++ b/colors.py @@ -96,3 +96,15 @@ ] +def palette_to_pixmap(palette): + pixmap = QG.QPixmap(QC.QSize(80, 20)) + painter = QG.QPainter(pixmap) + palette = [QG.QColor(NES_PALETTE[colour_idx]) for colour_idx in palette] + for idx, colour in enumerate(palette): + painter.setPen(colour) + brush = QG.QBrush() + brush.setColor(colour) + brush.setStyle(QC.Qt.SolidPattern) + painter.setBrush(brush) + painter.drawRect(idx*20, 0, idx*20 + 19, 19) + return pixmap