本文整理汇总了Python中PyQt5.QtGui.QBrush.setColor方法的典型用法代码示例。如果您正苦于以下问题:Python QBrush.setColor方法的具体用法?Python QBrush.setColor怎么用?Python QBrush.setColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QBrush
的用法示例。
在下文中一共展示了QBrush.setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createArrow
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def createArrow(self):
# add an arrow to destination line
myLine = self.destinationLine.line()
myLine.setLength(myLine.length() - TransitionGraphicsItem.ARROW_SIZE)
rotatePoint = myLine.p2() - self.destinationLine.line().p2()
rightPointX = rotatePoint.x() * math.cos(math.pi / 6) - rotatePoint.y() * math.sin(math.pi / 6)
rightPointY = rotatePoint.x() * math.sin(math.pi / 6) + rotatePoint.y() * math.cos(math.pi / 6)
rightPoint = QPointF(rightPointX + self.destinationLine.line().x2(),
rightPointY + self.destinationLine.line().y2())
leftPointX = rotatePoint.x() * math.cos(-math.pi / 6) - rotatePoint.y() * math.sin(-math.pi / 6)
leftPointY = rotatePoint.x() * math.sin(-math.pi / 6) + rotatePoint.y() * math.cos(-math.pi / 6)
leftPoint = QPointF(leftPointX + self.destinationLine.line().x2(),
leftPointY + self.destinationLine.line().y2())
polygon = QPolygonF()
polygon << rightPoint << leftPoint << self.destinationLine.line().p2() << rightPoint
if self.arrow == None:
self.arrow = QGraphicsPolygonItem(polygon, self)
else:
self.arrow.setPolygon(polygon)
brush = QBrush(Qt.SolidPattern)
brush.setColor(Qt.black)
self.arrow.setBrush(brush)
示例2: QMarkablePicture
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
class QMarkablePicture(QLabel):
def __init__(self, parent=None):
QLabel.__init__(self, parent)
self.initBrush()
self.marks = []
self.is_marks_count_limited = False
self.marks_count_limit = 0
def initBrush(self):
self.brush = QBrush(Qt.SolidPattern)
self.brush.setColor(QColor(constants.defaultBrushColor))
def paintEvent(self, e):
QLabel.paintEvent(self, e)
painter = QPainter()
painter.begin(self)
painter.setBrush(self.brush)
for mark in self.marks:
painter.drawEllipse(mark, constants.ellipsWidth, constants.ellipsHeight)
painter.end()
def setBrushColor(self, color):
self.brush.setColor(color)
def drawMark(self, mark):
if self.__isAbleDrawMark():
self.marks.append(mark)
self.update()
def removeMark(self, mark):
for painted_mark in self.marks:
if self.__isApproximatelyEqual(mark, painted_mark, constants.epsilon):
self.marks.remove(painted_mark)
break
self.update()
def getMarks(self):
return self.marks.copy()
def setMarksCountLimit(self, limit):
self.is_marks_count_limited = True
self.marks_count_limit = limit
def __isAbleDrawMark(self):
limit_enabled_condition = self.is_marks_count_limited and (len(self.marks) < self.marks_count_limit)
limit_disabled_condition = not self.is_marks_count_limited
return limit_enabled_condition or limit_disabled_condition
def __isApproximatelyEqual(self, firstMark, secondMark, epsilon):
full_equality = firstMark == secondMark
x_top_limit = (firstMark.x() + epsilon) >= secondMark.x()
x_bottom_limit = (firstMark.x() - epsilon) <= secondMark.x()
x_equality = x_top_limit and x_bottom_limit
y_top_limit = (firstMark.y() + epsilon) >= secondMark.y()
y_bottom_limit = (firstMark.y() - epsilon) <= secondMark.y()
y_equality = y_top_limit and y_bottom_limit
return full_equality or (x_equality and y_equality)
示例3: ModCrossButton
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
class ModCrossButton(QPushButton):
def __init__(self,parent,path=None):
QPushButton.__init__(self,parent)
self.parent=parent
#self.setAttribute(Qt.WA_TranslucentBackground, True)
self.backgroundColor = QPalette().light().color()
self.backgroundColor.setRgb(157,157,157) #(220,203,231)
#self.backgroundColor.setAlpha(100)
self.brush=QBrush(Qt.SolidPattern)
def paintEvent(self,event):
self.wide=self.width()
self.high=self.height()
self.xdis=self.wide/7
self.ydis=self.xdis
self.path=QPainterPath()
self.path.setFillRule(Qt.OddEvenFill)
self.path.moveTo(self.wide/2, self.high/2-self.xdis)
self.path.arcTo(0,0, self.wide, self.high,0,360)
#self.path.closeSubpath()
self.path.moveTo(self.wide/2-self.xdis/2, self.ydis)
self.path.lineTo(self.wide/2-self.xdis/2, self.high/2-self.xdis/2)
self.path.lineTo(self.ydis, self.high/2-self.xdis/2)
self.path.lineTo(self.ydis, self.high/2+self.xdis/2)
self.path.lineTo(self.wide/2-self.xdis/2, self.high/2+self.xdis/2)
self.path.lineTo(self.wide/2-self.xdis/2, self.high-self.ydis)
self.path.lineTo(self.wide/2+self.xdis/2, self.high-self.ydis)
self.path.lineTo(self.wide/2+self.xdis/2, self.high/2+self.xdis/2)
self.path.lineTo(self.wide-self.ydis, self.high/2+self.xdis/2)
self.path.lineTo(self.wide-self.ydis, self.high/2-self.xdis/2)
self.path.lineTo(self.wide/2+self.xdis/2, self.high/2-self.xdis/2)
self.path.lineTo(self.wide/2+self.xdis/2, self.ydis)
self.path.closeSubpath()
self.brush.setColor(self.backgroundColor)
self.painter=QPainter(self)
self.painter.setRenderHint(QPainter.Antialiasing)
self.painter.setPen(Qt.NoPen)
self.painter.setBrush(self.brush)
self.painter.drawPath(self.path)
self.painter.end()
#def mousePressEvent(self,ev):
# self.parent.close()
def enterEvent(self,ev):
self.backgroundColor.setRgb(242,146,52)
self.update()
def leaveEvent(self,ev):
self.backgroundColor.setRgb(157,157,157)
self.update()
示例4: drawCircle
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def drawCircle(self, painter, centerX, centerY, color, size):
pen = QPen(color, size)
painter.setPen(pen)
brush = QBrush(Qt.SolidPattern)
brush.setColor(QColor(Qt.blue))
painter.setBrush(brush)
painter.drawEllipse(centerX, centerY, 5, 5)
示例5: RoundedPushButton1
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
class RoundedPushButton1(QPushButton):
def __init__(self,parent, default_wide, default_high,text=''):
QPushButton.__init__(self, parent)
#self.resize(100,80)
self.default_high=default_high
self.default_wide=default_wide
self.xrd=self.default_wide/10
#self.yrd=self.default_high/10
self.yrd=self.xrd
#self.resize(self.default_wide,self.default_high)
self.backgroundColor = QPalette().light().color()
self.backgroundColor.setRgb(157,157,157) #(220,203,231)
#self.backgroundColor.setAlpha(0)
self.brush=QBrush(Qt.SolidPattern)
self.textlabel=textQLabel(self,text)
def paintEvent(self,event):
#brush.setStyle(Qt.Dense1Pattern)
self.brush.setColor(self.backgroundColor)
self.painter=QPainter(self)
self.painter.setRenderHint(QPainter.Antialiasing)
self.painter.setPen(Qt.NoPen)
self.painter.setBrush(self.brush)
self.painter.drawRoundedRect(QRect(0,0,self.default_wide,self.default_high), self.xrd, self.yrd)
#self.painter.drawPixmap(self.imgx, self.imgy, self.piximg)
self.painter.end()
示例6: setStyle
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def setStyle(self, painter, fillColor, penColor, stroke):
brush = QBrush()
pen = QPen(penColor, stroke)
brush.setColor(fillColor)
brush.setStyle(Qt.SolidPattern)
painter.setBrush(brush)
painter.setPen(pen)
painter.setRenderHint(QPainter.Antialiasing)
示例7: setRequired
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def setRequired(self, required):
self.required = required
brush = QBrush()
if required:
brush.setColor(QColor(255, 0, 0))
else:
brush.setColor(QColor(0, 0, 0))
self.setForeground(0, brush)
示例8: ModCloseButton
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
class ModCloseButton(QPushButton):
def __init__(self,parent,wide,high,ppath=None):
QPushButton.__init__(self,parent)
self.parent=parent
self.wide=wide
self.high=high
self.resize(self.wide,self.high)
self.xdis=self.wide/10
#self.setAttribute(Qt.WA_TranslucentBackground, True)
self.backgroundColor = QPalette().light().color()
self.backgroundColor.setRgb(157,157,157) #(220,203,231)
#self.backgroundColor.setAlpha(100)
self.brush=QBrush(Qt.SolidPattern)
if ppath :
self.path=ppath
else :
self.path=QPainterPath()
self.path.moveTo(self.wide/2, self.high/2-self.xdis)
self.path.arcTo(0,0, self.wide-2*self.xdis, self.high-2*self.xdis,45,90)
self.path.closeSubpath()
self.path.moveTo(self.wide/2-self.xdis, self.high/2)
self.path.arcTo(0,0,self.wide-2*self.xdis,self.high-2*self.xdis,135,90)
self.path.closeSubpath()
self.path.moveTo(self.wide/2, self.high/2+self.xdis)
self.path.arcTo(0,0,self.wide-2*self.xdis, self.high-2*self.xdis,225,90)
self.path.closeSubpath()
self.path.moveTo(self.wide/2+self.xdis, self.high/2)
self.path.arcTo(0,0,self.wide-2*self.xdis, self.high-2*self.xdis,315,90)
self.path.closeSubpath()
def paintEvent(self,event):
self.brush.setColor(self.backgroundColor)
self.painter=QPainter(self)
self.painter.setRenderHint(QPainter.Antialiasing)
self.painter.setPen(Qt.NoPen)
self.painter.setBrush(self.brush)
self.painter.drawPath(self.path)
self.painter.end()
def mousePressEvent(self,ev):
self.parent.close()
def enterEvent(self,ev):
self.backgroundColor.setRgb(234,39,13)
self.update()
def leaveEvent(self,ev):
self.backgroundColor.setRgb(157,157,157)
self.update()
示例9: valueChanged
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def valueChanged(self, property, value):
if (not self.propertyToId.contains(property)):
return
if (not self.currentItem or self.currentItem.isNone()):
return
tp = type(value)
id = self.propertyToId[property]
if tp == float:
if (id == "xpos"):
self.currentItem.setX(value)
elif (id == "ypos"):
self.currentItem.setY(value)
elif (id == "zpos"):
self.currentItem.setZ(value)
elif tp == str:
if (id == "text"):
if (self.currentItem.rtti() == RttiValues.Rtti_Text):
i = self.currentItem
i.setText(value)
elif tp == QColor:
if (id == "color"):
if (self.currentItem.rtti() == RttiValues.Rtti_Text):
i = self.currentItem
i.setColor(value)
elif (id == "brush"):
if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
i = self.currentItem
b = QBrush(i.brush())
b.setColor(value)
i.setBrush(b)
elif (id == "pen"):
if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Line):
i = self.currentItem
p = QPen(i.pen())
p.setColor(value)
i.setPen(p)
elif tp == QFont:
if (id == "font"):
if (self.currentItem.rtti() == RttiValues.Rtti_Text):
i = self.currentItem
i.setFont(value)
elif tp == QPoint:
if (self.currentItem.rtti() == RttiValues.Rtti_Line):
i = self.currentItem
if (id == "endpoint"):
i.setPoints(i.startPoint().x(), i.startPoint().y(), value.x(), value.y())
elif tp == QSize:
if (id == "size"):
if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle):
i = self.currentItem
i.setSize(value.width(), value.height())
elif (self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
i = self.currentItem
i.setSize(value.width(), value.height())
self.canvas.update()
示例10: paintEvent
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def paintEvent(self, ev):
pen = QPen()
pen.setStyle(Qt.DotLine)
pen.setWidth(2)
pen.setColor(QColor(Qt.white))
brush = QBrush()
brush.setStyle(Qt.SolidPattern)
brush.setColor(QColor(0, 0, 0))
painter = QPainter(self)
painter.setPen(pen)
painter.setBrush(brush)
painter.drawRect(ev.rect())
示例11: __init__
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def __init__(self, dblock: DBlock):
super(DBlockTreeItem, self).__init__(dblock, dblock.name)
self.dblock = dblock
self.setSelectable(False)
self.setEditable(False)
self.tool_tip = "DBlock: " + dblock.name
if isinstance(dblock, DEvent):
brush = QBrush()
brush.setColor(Qt.magenta)
self.tool_tip = "DEvent: " + dblock.name
self.setForeground(brush)
self.setSelectable(True)
示例12: WLLineLabel
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
class WLLineLabel(QPushButton):
def __init__(self,parent):
super(WLLineLabel,self).__init__(parent)
self.setWindowFlags(Qt.FramelessWindowHint )
self.linelength=1000
self.lineheight=5
self.resize(self.linelength, self.lineheight)
self.move(100,100)
self.stats=None
#self.setStyleSheet("{background-color:transparent;border:none;color:transparent;}")
self.backgroundColor = QPalette().light().color()
self.backgroundColor.setRgb(157,157,157)#(220,203,231)
#self.backgroundColor.setAlpha(255)
self.brush=QBrush(Qt.SolidPattern)
def paintEvent(self,event):
self.brush.setColor(self.backgroundColor)
self.painter=QPainter(self)
self.painter.setRenderHint(QPainter.Antialiasing)
self.painter.setPen(Qt.NoPen)
self.painter.setBrush(self.brush)
#print(self.geometry())
self.painter.drawRect(0, 0, 1000, 5)
self.painter.end()
def statsReset(self):
self.stats=None
self.backgroundColor.setAlpha(255)
self.redraw()
def mousePressEvent(self,ev):
if self.stats == 'selected' :
self.stats = None
self.backgroundColor.setAlpha(255)
else:
self.stats = 'selected'
self.backgroundColor.setRgb(157,157,157)
self.update()
def enterEvent(self,ev):
#print('enter')
if self.stats != 'selected' :
self.backgroundColor.setAlpha(0)
self.update()
def leaveEvent(self,ev):
if self.stats != 'selected' :
self.backgroundColor.setAlpha(255)
self.update()
示例13: setupMounts
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def setupMounts(self):
adapter = app.adapterManager[0]
if not adapter.useXwared:
self.tab_mount.setEnabled(False)
return
self.table_mounts.setRowCount(0)
self.table_mounts.clearContents()
mountsMapping = app.adapterManager[0].mountsFaker.getMountsMapping()
for i, mount in enumerate(app.adapterManager[0].mountsFaker.mounts):
self.table_mounts.insertRow(i)
# drive1: the drive letter it should map to, by alphabetical order
drive1 = app.adapterManager[0].mountsFaker.driveIndexToLetter(i)
self.table_mounts.setItem(i, 0, QTableWidgetItem(drive1 + "\\TDDOWNLOAD"))
# mounts = ['/path/to/1', 'path/to/2', ...]
self.table_mounts.setItem(i, 1, QTableWidgetItem(mount))
# drive2: the drive letter it actually is assigned to
drive2 = mountsMapping.get(mount, "无")
errors = []
# check: mapping
if drive1 != drive2:
errors.append(
"错误:盘符映射在'{actual}',而不是'{should}'。\n"
"如果这是个新挂载的文件夹,请尝试稍等,或重启后端,可能会修复此问题。"
.format(actual = drive2, should = drive1))
brush = QBrush()
if errors:
brush.setColor(Qt.red)
errString = "\n".join(errors)
else:
brush.setColor(Qt.darkGreen)
errString = "正常"
errWidget = QTableWidgetItem(errString)
errWidget.setForeground(brush)
self.table_mounts.setItem(i, 2, errWidget)
del brush, errWidget
self.table_mounts.resizeColumnsToContents()
示例14: setupMounts
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
def setupMounts(self):
self.table_mounts.setRowCount(0)
self.table_mounts.clearContents()
permissionCheckResult = app.mountsFaker.permissionCheck()
permissionCheckFailed = ["无法获得检测权限。运行{}查看原因。".format(constants.PERMISSIONCHECK)]
mountsMapping = app.mountsFaker.getMountsMapping()
for i, mount in enumerate(app.mountsFaker.mounts):
# mounts = ['/path/to/1', 'path/to/2', ...]
self.table_mounts.insertRow(i)
self.table_mounts.setItem(i, 0, QTableWidgetItem(mount))
# drive1: the drive letter it should map to, by alphabetical order
drive1 = chr(ord('C') + i) + ":"
self.table_mounts.setItem(i, 1, QTableWidgetItem(drive1))
# drive2: the drive letter it actually is assigned to
drive2 = mountsMapping.get(mount, "无")
# check 1: permission
errors = permissionCheckResult.get(mount, permissionCheckFailed)
# check 2: mapping
if drive1 != drive2:
errors.append(
"警告:盘符映射在'{actual}',而不是'{should}'。需要重启后端修复。".format(
actual = drive2,
should = drive1))
brush = QBrush()
if errors:
brush.setColor(Qt.red)
errString = "\n".join(errors)
else:
brush.setColor(Qt.darkGreen)
errString = "正常"
errWidget = QTableWidgetItem(errString)
errWidget.setForeground(brush)
self.table_mounts.setItem(i, 2, errWidget)
del brush, errWidget
self.table_mounts.resizeColumnsToContents()
示例15: RoundedPushButton
# 需要导入模块: from PyQt5.QtGui import QBrush [as 别名]
# 或者: from PyQt5.QtGui.QBrush import setColor [as 别名]
class RoundedPushButton(QPushButton):
def __init__(self,parent, text=''):
QPushButton.__init__(self, parent)
self.text=text
self.backgroundColor = QPalette().light().color()
self.backgroundColor.setRgb(157,157,157) #(220,203,231)
#self.backgroundColor.setAlpha(0)
self.brush=QBrush(Qt.SolidPattern)
def paintEvent(self,event):
self.brush.setColor(self.backgroundColor)
self.painter=QPainter(self)
self.painter.setRenderHint(QPainter.Antialiasing)
self.painter.setPen(Qt.NoPen)
self.painter.setBrush(self.brush)
self.painter.drawRoundedRect(QRect(0,0,self.width(),self.height()), self.width()/10, self.height()/10)
self.painter.end()
self.painter3=QPainter(self)
self.painter3.drawText(1,0,self.width()-2,self.height(),Qt.AlignCenter,self.text)
self.painter3.end()