Reputation: 1476
I know this is possible, but I cannot for the life of me get the proper code to work. What I want is very simple: a monochromatic rectangle, size, say 20x20 constructed (presumably) through a QPainter. From that I wish to use the painted rectangle as a QIcon for use in a QComboBox. Any ideas? Thanks in advance.
Upvotes: 0
Views: 1899
Reputation: 120768
Looks like you just need QPixmap.fill
for this:
from PyQt4 import QtGui
class Window(QtGui.QComboBox):
def __init__(self):
QtGui.QComboBox.__init__(self)
self.resize(200, 25)
pixmap = QtGui.QPixmap(20, 20)
for color in 'red orange yellow green blue grey violet'.split():
pixmap.fill(QtGui.QColor(color))
self.addItem(QtGui.QIcon(pixmap), color.title())
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec_())
Upvotes: 3