我有一个从QColorDialog.getColor()获得的QColor。我想在表单中将其显示给用户。
我该怎么做呢?
我尝试使用QGraphicView并像这样设置backgroundBrush:
self.displayColor = QtGui.QGraphicView(self)
self.color = QtGui.QColor(category.color)
self.displayColor.setBackgroundBrush(QtGui.QBrush(self.color))但是即使我改变了背景笔刷,小工具仍然是白色的。
怎样才能强制它重新绘制背景呢?
谢谢
发布于 2011-01-07 23:42:22
最后,我选择像这样创建一个小部件:
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
class ColorDisplay(QtGui.QWidget):
def __init__(self, parent):
super(ColorDisplay, self).__init__(parent)
self.color = None
def setColor(self, color):
self.color = QtGui.QColor(color)
self.update()
def paintEvent(self, event=None):
painter = QtGui.QPainter(self)
if self.color is not None:
painter.setBrush(QtGui.QBrush(self.color))
painter.drawRect(self.rect())
def getColorName(self):
return unicode(self.color.name())我可以使用setColor()更改颜色。
发布于 2011-01-07 21:00:31
s=QGraphicsScene()
s.setBackgroundBrush(QColor(0,255,0))
g=QGraphicsView(s)
g.render(QPainter())https://stackoverflow.com/questions/4624985
复制相似问题