本文整理汇总了Python中PySide.QtGui.QPen.setColor方法的典型用法代码示例。如果您正苦于以下问题:Python QPen.setColor方法的具体用法?Python QPen.setColor怎么用?Python QPen.setColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPen
的用法示例。
在下文中一共展示了QPen.setColor方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paint(self, canvas, is_secondary_color=False, additional_flag=False):
pen = QPen()
if is_secondary_color:
pen.setColor(self.data_singleton.secondary_color)
else:
pen.setColor(self.data_singleton.primary_color)
painter = QPainter(canvas.image)
painter.setRenderHint(QPainter.Antialiasing)
pen.setWidth(self.data_singleton.pen_size)
pen.setStyle(Qt.SolidLine)
pen.setCapStyle(Qt.RoundCap)
pen.setJoinStyle(Qt.RoundJoin)
painter.setPen(pen)
if is_secondary_color:
painter.setBrush(self.data_singleton.primary_color)
else:
painter.setBrush(self.data_singleton.secondary_color)
if self._start_point != self._end_point:
painter.drawRect(QRect(self._start_point, self._end_point))
painter.end()
canvas.edited = True
canvas.update()
示例2: paintEvent
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paintEvent(self, pe):
if not self._hover_rect:
super(TrackerWebView, self).paintEvent(pe)
else:
super(TrackerWebView, self).paintEvent(pe)
hover_rect = self._hover_rect
self._fixRectForScroll(hover_rect)
painter = QPainter(self)
painter.save()
pen = QPen(Qt.red)
pen.setWidth(2)
painter.setPen(pen)
painter.drawRect(hover_rect)
painter.restore()
# draw green rects around the similar elements
pen = QPen()
pen.setWidth(2)
for field_info in self._fields_info:
painter.save()
web_elements = field_info.web_elements
color = field_info.color
pen.setColor(color)
painter.setPen(pen)
for elem in web_elements:
elem_rect = elem.absoluteGeometry()
painter.drawRoundedRect(self._fixRectForScroll(elem_rect), 2, 2)
painter.restore()
示例3: paintEvent
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paintEvent(self, pe):
# make an arrow polygon right in the middle
painter = QPainter(self)
painter.setPen(Qt.NoPen)
# draw the background transparent rect
painter.save()
painter.setOpacity(self.BACKGROUND_OPACITY)
# get the rectangle coordinates it should extend over the whole width with only a portion at the center
painter.setBrush(Qt.black)
empty_space_percent = 1 - self.BACKROUND_HEIGHT_PERCENT
rect_top = empty_space_percent / 2 * self.height()
rect_height = self.BACKROUND_HEIGHT_PERCENT * self.height()
painter.drawRect(0, rect_top, self.width(), rect_height)
painter.restore()
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen()
pen.setWidth(self.ARROW_LINE_WIDTH)
pen.setCapStyle(Qt.RoundCap)
if self._mouse_inside:
pen.setColor(self._hover_color)
else:
pen.setColor(self._normal_color)
# get the arrow coords
painter.setPen(pen)
self_center = QPointF(self.width() / 2, self.height() / 2) # use this as the arrow tip for now
if self._direction == self.LEFT:
h_shift = self._arrow_width
elif self._direction == self.RIGHT:
h_shift = - self._arrow_width
v_shift = self._arrow_height / 2
top_point = self_center + QPointF(h_shift, - v_shift)
bottom_point = self_center + QPointF(h_shift, v_shift)
painter.drawLine(top_point, self_center)
painter.drawLine(self_center, bottom_point)
示例4: __init__
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def __init__(self, parent, child):
''' Create a new connection between a parent and a child item '''
super(Connection, self).__init__(parent)
self.parent = parent
self.child = child
self._start_point = None
self._end_point = None
self._middle_points = []
pen = QPen()
pen.setColor(Qt.blue)
pen.setCosmetic(False)
self.setPen(pen)
self.parent_rect = parent.sceneBoundingRect()
self.childRect = child.sceneBoundingRect()
# Activate cache mode to boost rendering by calling paint less often
self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
示例5: paint
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paint(self, painter, _, ___):
''' Draw the comment symbol '''
rect = self.boundingRect()
pen = QPen()
pen.setStyle(Qt.DashLine)
pen.setColor(Qt.darkGray)
painter.setPen(pen)
x, y, w, h = rect.x(), rect.y(), rect.width(), rect.height()
if self.on_the_right:
painter.drawLines([QPoint(w, y), QPoint(x, y),
QPoint(x, y), QPoint(x, h),
QPoint(x, h), QPoint(w, h)])
else:
painter.drawLines([QPoint(x, y), QPoint(w, y),
QPoint(w, y), QPoint(w, h),
QPoint(w, h), QPoint(x, h)])
示例6: draw_uvs
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def draw_uvs(self):
self.img = QPixmap(QSize(self.w, self.h))
pen = QPen()
pen.setWidth(int(self.pen_w.text()))
pen.setBrush(QBrush(Qt.white))
pen.setColor(QColor('white'))
painter = QPainter()
painter.begin(self.img)
painter.setPen(pen)
coords = self.get_coords()
for face in coords:
for n in xrange(len(face) - 1):
print face[n][0], face[n][1], face[n + 1][0], face[n + 1][1]
painter.drawLine(face[n][0], face[n][1], face[n + 1][0], face[n + 1][1])
painter.end()
self.view.scene().addPixmap(self.img)
示例7: paintEvent
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.setFont(self.font)
# painter.setPen(QColor(200, 0, 100))#light grey
painter.fillRect(event.rect(), self.background_color)
p=QPen()
p.setColor(QColor(100,100,100))
painter.setPen(p)
rect=event.rect()
rect.adjust(0,-1, self.adjust_width,1)
painter.drawRect(rect)
cw = self.parent()
block = cw.firstVisibleBlock()
blocknum = block.blockNumber()
top = cw.blockBoundingGeometry(block).translated(
cw.contentOffset()).top()
bottom = top + int(cw.blockBoundingRect(block).height())
lineno=self.start
while block.isValid() and top <= event.rect().bottom():
if block.isVisible() and bottom >= event.rect().top():
if blocknum>0:
text=block.text()
if not text.startswith(self.anti_tag):
painter.drawText(0, top, self.width() - 2,
self.fontMetrics().height(),
QtCore.Qt.AlignRight, str(lineno))
lineno+=1
else:
painter.drawText(0, top, self.width() - 2,
self.fontMetrics().height(),
QtCore.Qt.AlignRight, '...')
block = block.next()
top = bottom
bottom = top + int(cw.blockBoundingRect(block).height())
blocknum += 1
示例8: paintEvent
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
# Фон
painter_path = QPainterPath()
painter_path.addRect(0, 0, self.width() - 1, self.height() - 1)
painter.fillPath(painter_path,
QBrush(QImage(':/main/background.png')))
if self.image:
painter.drawText(10, 20, str(self.image.draw_scale))
painter.setTransform(QTransform().
scale(self.image.draw_scale, self.image.draw_scale).
translate(self.image.draw_offset.x(), self.image.draw_offset.y()))
old_pen = painter.pen()
new_pen = QPen()
new_pen.setColor(QColor(0, 150, 0))
painter.setPen(new_pen)
self.image.draw(painter)
painter.setPen(old_pen)
示例9: BaseObject
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
class BaseObject(QGraphicsPathItem):
"""
Subclass of `QGraphicsPathItem`_
TOWRITE
"""
Type = OBJ_TYPE_BASE
def __init__(self, parent=None):
"""
Default class constructor.
:param `parent`: Pointer to a parent widget instance.
:type `parent`: `QGraphicsItem`_
"""
super(BaseObject, self).__init__(parent)
qDebug("BaseObject Constructor()")
self.objPen = QPen() # QPen objPen;
self.lwtPen = QPen() # QPen lwtPen;
self.objLine = QLineF() # QLineF objLine;
self.objRubberMode = int() # int objRubberMode;
self.objRubberPoints = {} # QHash<QString, QPointF> objRubberPoints;
self.objRubberTexts = {} # QHash<QString, QString> objRubberTexts;
self.objID = int() # qint64 objID;
self.objPen.setCapStyle(Qt.RoundCap)
self.objPen.setJoinStyle(Qt.RoundJoin)
self.lwtPen.setCapStyle(Qt.RoundCap)
self.lwtPen.setJoinStyle(Qt.RoundJoin)
self.objID = QDateTime.currentMSecsSinceEpoch()
def __del__(self):
"""Class destructor."""
qDebug("BaseObject Destructor()")
def type(self):
"""
TOWRITE
:return: TOWRITE
:rtype: int
"""
return self.Type
def setObjectColor(self, color):
"""
TOWRITE
:param `color`: TOWRITE
:type `color`: `QColor`_
"""
self.objPen.setColor(color)
self.lwtPen.setColor(color)
def setObjectColorRGB(self, rgb):
"""
TOWRITE
:param `rgb`: TOWRITE
:type `rgb`: `QRgb`_
"""
self.objPen.setColor(QColor(rgb))
self.lwtPen.setColor(QColor(rgb))
def setObjectLineType(self, lineType):
"""
TOWRITE
:param `rgb`: TOWRITE
:type `rgb`: Qt.PenStyle
"""
self.objPen.setStyle(lineType)
self.lwtPen.setStyle(lineType)
def setObjectLineWeight(self, lineWeight):
"""
TOWRITE
:param `lineWeight`: TOWRITE
:type `lineWeight`: qreal
"""
self.objPen.setWidthF(0) # NOTE: The objPen will always be cosmetic
if lineWeight < 0:
if lineWeight == OBJ_LWT_BYLAYER:
self.lwtPen.setWidthF(0.35) # TODO: getLayerLineWeight
elif lineWeight == OBJ_LWT_BYBLOCK:
self.lwtPen.setWidthF(0.35) # TODO: getBlockLineWeight
else:
QMessageBox.warning(0, QObject.tr("Error - Negative Lineweight"),
QObject.tr("Lineweight: %f" % lineWeight))
qDebug("Lineweight cannot be negative! Inverting sign.")
self.lwtPen.setWidthF(-lineWeight)
else:
#.........这里部分代码省略.........
示例10: paintEvent
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paintEvent(self, event):
cX = self.parent.lytLeftMargin + self.scaleMarkLen
cY = self.parent.lytTopMargin + self.scaleMarkLen
worldX = self.parent.presenter.showChunkX*16
worldZ = self.parent.presenter.showChunkZ*16
painter = QPainter()
path = QPainterPath()
painter.begin(self)
painter.save()
#painter.setFont(QFont('Arial Narrow', 8)) #QFont.Bold
# draw scale
x = cX
y = cY
painter.rotate(-90)
for i in range(16):
fr = QRectF(-y, x, self.scaleMarkLen, self.edgeLen)
painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, str(worldX))
#painter.drawRect(fr)
#fr = QRectF(-y - 16*self.edgeLen - self.scaleMarkLen, x, self.scaleMarkLen, self.edgeLen)
#painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
#painter.drawRect(fr)
x += self.edgeLen
worldX += 1
painter.rotate(90)
x = self.parent.lytLeftMargin
y = cY
for i in range(16):
fr = QRectF(x, y, self.scaleMarkLen, self.edgeLen)
painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, str(worldZ))
#painter.drawRect(fr)
#fr = QRectF(x + self.scaleMarkLen + 16*self.edgeLen, y, self.scaleMarkLen, self.edgeLen)
#painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
#painter.drawRect(fr)
y += self.edgeLen
worldZ += 1
x = cX
y = cY
for i in range(16):
for j in range(16):
path.addRect(x, y, self.edgeLen, self.edgeLen)
#fr = QRectF(x, y, self.edgeLen, self.edgeLen)
#painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
x += self.edgeLen
x = cX
y += self.edgeLen
painter.drawPath(path)
slice_ = self.parent.presenter.getSlice(self.parent.presenter.elevation)
x = cX
y = cY
bru = QBrush()
#path1 = QPainterPath()
for i in range(16):
for j in range(16):
if slice_[i][j] in self.parent.selectedMinerals.list_:
lePen = painter.pen()
newPen = QPen(bru, 3)
newPen.setColor(self.parent.selectedMinerals.getColor(slice_[i][j]))
painter.setPen(newPen)
painter.drawRect(x, y, self.edgeLen, self.edgeLen)
painter.setPen(lePen)
x += self.edgeLen
x = cX
y += self.edgeLen
painter.restore()
painter.end()
del painter
示例11: paintEvent
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def paintEvent( self, event ):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(painter.Antialiasing)
font = painter.font()
font.setBold(True)
painter.setFont(font)
x = self.rect().x()
y = self.rect().y()
w = self.rect().width() - 1
h = self.rect().height() - 1
r = 8
# draw a rounded style
if self._rolloutStyle == 2:
# draw the text
painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
# draw the triangle
self.__drawTriangle(painter, x, y)
# draw the borders
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.6)
painter.setPen(pen)
painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)
pen.setColor(self.palette().color(QPalette.Shadow))
painter.setPen(pen)
painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)
# draw a square style
if self._rolloutStyle == 3:
# draw the text
painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
self.__drawTriangle(painter, x, y)
# draw the borders
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.6)
painter.setPen(pen)
painter.drawRect(x + 1, y + 1, w - 1, h - 1)
pen.setColor(self.palette().color(QPalette.Shadow))
painter.setPen(pen)
painter.drawRect(x, y, w - 1, h - 1)
# draw a Maya style
if self._rolloutStyle == 4:
# draw the text
painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
painter.setRenderHint(QPainter.Antialiasing, False)
self.__drawTriangle(painter, x, y)
# draw the borders - top
headerHeight = 20
headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)
# Highlight
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.4)
painter.setPen(pen)
painter.drawRect(headerRect)
painter.fillRect(headerRect, QColor(255, 255, 255, 18))
# Shadow
pen.setColor(self.palette().color(QPalette.Dark))
painter.setPen(pen)
painter.drawRect(headerRectShadow)
if not self.isCollapsed():
# draw the lover border
pen = QPen(self.palette().color(QPalette.Dark))
pen.setWidthF(0.8)
painter.setPen(pen)
offSet = headerHeight + 3
bodyRect = QRect(x, y + offSet, w, h - offSet)
bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
painter.drawRect(bodyRect)
pen.setColor(self.palette().color(QPalette.Light))
pen.setWidthF(0.4)
painter.setPen(pen)
painter.drawRect(bodyRectShadow)
# draw a boxed style
elif self._rolloutStyle == 1:
#.........这里部分代码省略.........
示例12: SelectBox
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
class SelectBox(QRubberBand):
"""
Subclass of `QRubberBand`_
TOWRITE
"""
def __init__(self, s, parent=None):
"""
Default class constructor.
:param `s`: TOWRITE
:type `s`: QRubberBand.Shape
:param `parent`: Pointer to a parent widget instance.
:type `parent`: `QWidget`_
"""
super(SelectBox, self).__init__(s, parent)
# private
self._leftBrushColor = QColor()
self._rightBrushColor = QColor()
self._leftPenColor = QColor()
self._rightPenColor = QColor()
self._alpha = 255 # quint8 #: TODO: what is the initial int?
self._dirBrush = QBrush()
self._leftBrush = QBrush()
self._rightBrush = QBrush()
self._dirPen = QPen()
self._leftPen = QPen()
self._rightPen = QPen()
self._boxDir = False #: TODO: is this initial bool value right?
# Default values
self.setColors(QColor(Qt.darkGreen), QColor(Qt.green), QColor(Qt.darkBlue), QColor(Qt.blue), 32)
def paintEvent(self, event):
"""
Handles the ``paintEvent`` event for :class:`SelectBox`.
:param `event`: A `QPaintEvent`_ to be processed.
"""
painter = QPainter(self)
painter.setPen(self._dirPen)
width, height = self.width(), self.height()
painter.fillRect(0, 0, width - 1, height - 1, self._dirBrush)
painter.drawRect(0, 0, width - 1, height - 1)
def forceRepaint(self):
"""
Force repaint the rubberband.
.. NOTE:: HACK: Take that QRubberBand!
"""
# HACK: Take that QRubberBand!
hack = self.size() # QSize
self.resize(hack + QSize(1, 1))
self.resize(hack)
# Slots ------------------------------------------------------------------
@Slot(int)
def setDirection(self, dir):
"""
TOWRITE
:param `dir`: TOWRITE
:type `dir`: int
"""
if not dir:
self._dirPen = self._leftPen
self._dirBrush = self._leftBrush
else:
self._dirPen = self._rightPen
self._dirBrush = self._rightBrush
self._boxDir = dir
@Slot(QColor, QColor, QColor, QColor, int)
def setColors(self, colorL, fillL, colorR, fillR, newAlpha):
"""
TOWRITE
:param `colorL`: TOWRITE
:type `colorL`: `QColor`_
:param `fillL`: TOWRITE
:type `fillL`: `QColor`_
:param `colorR`: TOWRITE
:type `colorR`: `QColor`_
:param `fillR`: TOWRITE
:type `fillR`: `QColor`_
:param `newAlpha`: TOWRITE
:type `newAlpha`: int
"""
qDebug("SelectBox setColors()")
self._alpha = newAlpha
self._leftPenColor = colorL # TODO: allow customization
self._leftBrushColor = QColor(fillL.red(), fillL.green(), fillL.blue(), self._alpha)
#.........这里部分代码省略.........
示例13: draw
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def draw(self, painter, scale):
if self.point:
pen = QPen()
pen.setColor(QColor(255, 0, 0))
painter.setPen(pen)
painter.drawEllipse(self.point, Figure.CTRL_RADIUS + 4, Figure.CTRL_RADIUS + 4)
示例14: random
# 需要导入模块: from PySide.QtGui import QPen [as 别名]
# 或者: from PySide.QtGui.QPen import setColor [as 别名]
def random():
pen = QPen()
pen.setColor(QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
point = Point(100. * random.random(), 100. * random.random())
size = Size(5 + 100. * random.random(), 5 + 100. * random.random())
return Rect(point, size, pen)