本文整理汇总了Python中PyQt5.QtGui.QBrush类的典型用法代码示例。如果您正苦于以下问题:Python QBrush类的具体用法?Python QBrush怎么用?Python QBrush使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QBrush类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RoundedPushButton1
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()
示例2: ModCrossButton
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()
示例3: QMarkablePicture
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)
示例4: __init__
def __init__(self, parent = None, message = None, itemType = "log"):
QListWidgetItem.__init__(self)
self.itemType = itemType
if (itemType == "log"):
self.setText("--- " + str(message))
elif (itemType == "in"):
self.setText("<<< " + str(message))
elif (itemType == "out"):
self.setText(">>> " + str(message))
else:
self.setText(str(message))
font = QFont()
font.setFamily("Monospace")
if (itemType == "in") or (itemType == "out"):
font.setBold(True)
font.setWeight(75)
else:
font.setBold(False)
font.setWeight(50)
self.setFont(font)
brush = QBrush(QColor(0, 0, 0))
if (itemType == "in"):
brush = QBrush(QColor(0, 0, 85))
elif (itemType == "out"):
brush = QBrush(QColor(0, 85, 0))
brush.setStyle(Qt.NoBrush)
self.setForeground(brush)
示例5: drawCircle
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)
示例6: createArrow
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)
示例7: setStyle
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)
示例8: setRequired
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)
示例9: ModCloseButton
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()
示例10: __set_brushAlpha
def __set_brushAlpha(self, alpha: int):
"""
Args:
alpha: Description
"""
brush = QBrush(self.item.brush())
color = QColor(brush.color())
color.setAlpha(alpha)
self.item.setBrush(QBrush(color))
示例11: valueChanged
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()
示例12: paintEvent
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())
示例13: __set_brushAlpha
def __set_brushAlpha(self, alpha):
"""Summary
Args:
alpha (TYPE): Description
Returns:
TYPE: Description
"""
brush = QBrush(self.item.brush())
color = QColor(brush.color())
color.setAlpha(alpha)
self.item.setBrush(QBrush(color))
示例14: __init__
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)
示例15: WLLineLabel
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()