本文整理汇总了Python中PySide.QtGui.QPainter.fillRect方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.fillRect方法的具体用法?Python QPainter.fillRect怎么用?Python QPainter.fillRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.fillRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawIconWithShadow
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def drawIconWithShadow(icon, rect, p, iconMode, radius, color, offset):
cache = QPixmap()
pixmapName = "icon {0} {1} {2}".format(icon.cacheKey(), iconMode, rect.height())
if not QPixmapCache.find(pixmapName, cache):
px = icon.pixmap(rect.size())
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
cache.fill(Qt.transparent)
cachePainter = QPainter(cache)
if iconMode == QIcon.Disabled:
im = px.toImage().convertToFormat(QImage.Format_ARGB32)
for y in range(im.height()):
scanLine = im.scanLine(y)
for x in range(im.width()):
pixel = scanLine
intensity = qGray(pixel)
scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel))
scanLine += 1
px = QPixmap.fromImage(im)
# Draw shadow
tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1), QImage.Format_ARGB32_Premultiplied)
tmp.fill(Qt.transparent)
tmpPainter = QPainter(tmp)
tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
tmpPainter.drawPixmap(QPoint(radius, radius), px)
tmpPainter.end()
# blur the alpha channel
blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
blurred.fill(Qt.transparent)
blurPainter = QPainter(blurred)
# todo : blur image
blurPainter.end()
tmp = blurred
# blacken the image
tmpPainter.begin(tmp)
tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
tmpPainter.fillRect(tmp.rect(), color)
tmpPainter.end()
tmpPainter.begin(tmp)
tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
tmpPainter.fillRect(tmp.rect(), color)
tmpPainter.end()
# draw the blurred drop shadow...
cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp)
# Draw the actual pixmap...
cachePainter.drawPixmap(QPoint(radius, radius) + offset, px)
QPixmapCache.insert(pixmapName, cache)
targetRect = cache.rect()
targetRect.moveCenter(rect.center())
p.drawPixmap(targetRect.topLeft() - offset, cache)
示例2: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, event):
""" Paints the widgets:
- paints the background
- paint each visible blocks that intersects the widget bbox.
"""
painter = QPainter(self)
painter.fillRect(event.rect(), self.back_brush)
painter.setPen(self.text_pen)
painter.setFont(self.font)
w = self.width() - 2
# better name lookup speed
painter_drawText = painter.drawText
align_right = Qt.AlignRight
normal_font = painter.font()
normal_font.setBold(False)
bold_font = QFont(normal_font)
bold_font.setBold(True)
active = self.editor.codeEdit.textCursor().blockNumber()
for vb in self.editor.codeEdit.visible_blocks:
row = vb.row
if row == active + 1:
painter.setFont(bold_font)
else:
painter.setFont(normal_font)
painter_drawText(0, vb.top, w, vb.height, align_right,
str(row))
return Panel.paintEvent(self, event)
示例3: __init__
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def __init__(self, parent, scene, view):
super(QNodesEditor, self).__init__(parent)
self.scene = scene
self.scene.installEventFilter(self)
gridSize = 25
gridMap = QPixmap(gridSize,gridSize)
gridPainter = QPainter(gridMap)
gridPainter.fillRect(0,0,gridSize,gridSize, QApplication.palette().window().color().darker(103))
gridPainter.fillRect(1,1,gridSize-2,gridSize-2, QApplication.palette().window())
gridPainter.end()
self.scene.setBackgroundBrush( QBrush(gridMap) )
originSize = 50
originItem = QGraphicsPathItem()
path = QPainterPath()
path.moveTo(0,-originSize)
path.lineTo(0,originSize)
path.moveTo(-originSize,0)
path.lineTo(originSize,0)
originItem.setPath(path)
originItem.setPen(QPen(QApplication.palette().window().color().darker(110),2))
originItem.setZValue(-2)
self.scene.addItem(originItem)
self.view = view
self.view.setDragMode(QGraphicsView.RubberBandDrag)
self.view.setRenderHint(QPainter.Antialiasing)
self.connection = None
示例4: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, e):
painter = QPainter()
painter.begin(self)
width = self.width()
height = self.height()
#Blank out the world
painter.fillRect(0, 0, width, height, Qt.white)
#Compute width/height of the columns and rows
#Reserve pixels for the grid lines
colWidth = (width - (self._NUM_COLS - 1) * self._GRID_SIZE) / self._NUM_COLS
rowHeight = (height - (self._NUM_ROWS - 1) * self._GRID_SIZE) / self._NUM_ROWS
colWidth = max(1, colWidth)
rowHeight = max(1, rowHeight)
#Perform drawing operations for world rendering
self._drawGrid(width, height, colWidth, rowHeight, painter)
self._drawObstacles(colWidth, rowHeight, painter)
if self._drawVisited:
self._drawVisitedCells(colWidth, rowHeight, painter)
if self._drawActive:
self._drawActiveCells(colWidth, rowHeight, painter)
self._drawStartAndEndCells(colWidth, rowHeight, painter)
self._drawCurrentCell(colWidth, rowHeight, painter)
if self._drawCheapestPath:
self._drawPath(colWidth, rowHeight, painter)
painter.end()
示例5: SetImageTransparency
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def SetImageTransparency(image, transparencyPercentage):
""" Set the Image Transparency to the value provided """
alpha = QImage(image)
painter = QPainter(alpha)
alphaValue = int(transparencyPercentage*255/100)
painter.fillRect(alpha.rect(), QColor(alphaValue, alphaValue, alphaValue))
painter.end()
image.setAlphaChannel(alpha)
示例6: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
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)
示例7: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, event):
""" Paints the widget """
if self.enabled is False:
return
Panel.paintEvent(self, event)
painter = QPainter(self)
painter.fillRect(event.rect(), self.back_brush)
for vb in self.editor.codeEdit.visible_blocks:
line = vb.row
# paint marker for line
marker = self.getIndicatorForLine(line)
if marker is None:
continue
# use the normal pen to draw the fold indicator
drawLines = False
pen = self.normal_pen
if marker.hover is True:
pen = self.highlight_pen
drawLines = True
painter.setPen(pen)
# get the text to draw
txt = '-'
if marker.folded is True:
drawLines = False
txt = '+'
offset = 4
h = self.size_hint.height()
fm = QFontMetricsF(self.editor.codeEdit.font())
hoffset = (fm.height() - h) / 2.0
r = QRect(vb.rect.x(), vb.rect.y() + hoffset, self.size_hint.width(), self.size_hint.height())
painter.setFont(self.font)
painter.drawText(r, Qt.AlignVCenter | Qt.AlignHCenter, txt)
w = self.size_hint.width() - 2 * offset
h = self.size_hint.width() - 2 * offset
hoffset = (fm.height() - h) / 2.0
r.setX(vb.rect.x() + offset)
r.setY(vb.rect.y() + hoffset)
r.setWidth(w)
r.setHeight(h)
painter.drawRect(r)
if drawLines is True:
top = (vb.rect.x() + self.size_hint.width() / 2.0,
vb.rect.y() + hoffset + offset * 2)
delta = ((marker.end - marker.start) * vb.height) # - (vb.rect.height() / 2.0)
bottom = (top[0], top[1] + delta)
painter.drawLine(top[0], top[1], bottom[0], bottom[1])
painter.drawLine(bottom[0], bottom[1], bottom[0] + self.size_hint.width() / 2.0, bottom[1])
return
示例8: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, event):
"""
Handles the ``paintEvent`` event for :class:`AboutDialog`.
:param `event`: a `QPaintEvent` event to be processed.
"""
rect = self.rect()
painter = QPainter(self)
painter.setRenderHint(painter.SmoothPixmapTransform)
# Always fill with a solid color first
painter.fillRect(rect, Qt.white)
# Then overlay the texture
painter.fillRect(rect, self.bgBrush)
示例9: _numberbar_paint
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def _numberbar_paint(self, number_bar, event):
'''Paint number bar.'''
font_metrics = self.fontMetrics()
current_line = self.edit.document().findBlock(
self.edit.textCursor().position()
).blockNumber() + 1
block = self.edit.firstVisibleBlock()
line_count = block.blockNumber()
painter = QPainter(number_bar)
painter.fillRect(event.rect(), self.palette().base())
# Iterate over all visible text blocks in the document.
while block.isValid():
line_count += 1
block_top = self.edit.blockBoundingGeometry(block).\
translated(self.edit.contentOffset()).top()
# Check if the position of the block is out side of the visible
# area.
if not block.isVisible() or block_top >= event.rect().bottom():
break
# We want the line number for the selected line to be bold.
if line_count == current_line:
font = painter.font()
font.setBold(True)
font.setUnderline(True)
painter.setFont(font)
else:
font = painter.font()
font.setBold(False)
font.setUnderline(False)
painter.setFont(font)
# Draw the line number right justified at the position of the
# line.
paint_rect = QRect(0, block_top, number_bar.width(),
font_metrics.height())
painter.drawText(paint_rect, Qt.AlignRight,
"{} ".format(unicode(line_count)))
block = block.next()
painter.end()
return
示例10: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, event):
""" Paints the widget """
if self.enabled is False:
return
Panel.paintEvent(self, event)
painter = QPainter(self)
painter.fillRect(event.rect(), self.back_brush)
for vb in self.editor.codeEdit.visible_blocks:
l = vb.row
marker = self.__getMarkerForLine(l)
if marker:
if marker.icon is not None:
r = QRect()
r.setX(vb.rect.x())
r.setY(vb.rect.y())
r.setWidth(self.size_hint.width())
r.setHeight(self.size_hint.height())
marker.icon.paint(painter, r)
return
示例11: addUnit
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def addUnit(self, unit):
global mapSize
unit.tile = self
self.units.append(unit)
img = QImage(unit.image).scaledToWidth(self.getImageRect().width())
if unit.owner:
rect = img.rect()
painter = QPainter(img)
painter.setPen(unit.owner.unitColor())
painter.drawEllipse(rect)
hpWidth = 20
greenWidth = unit.hp / float(unit.maxHp) * hpWidth
painter.fillRect(5, 5, greenWidth, 5, Qt.green)
painter.fillRect(5 + greenWidth, 5, hpWidth-greenWidth, 5, Qt.red)
painter.end()
image = QGraphicsPixmapItem(QPixmap(img), self)
if mapSize == 0:
mapSize = 1
image.setOffset(self.x + 12/(2*mapSize), self.y + 10/(2*mapSize))
self.unitImages.append(image)
示例12: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, event):
"""
Handles the ``paintEvent`` event for :class:`MdiArea`.
:param `event`: A `QPaintEvent`_ to be processed.
"""
vport = self.viewport()
rect = vport.rect()
painter = QPainter(vport)
painter.setRenderHint(painter.SmoothPixmapTransform)
# Always fill with a solid color first
if self.useColor:
# painter.fillRect(rect, self.colorBrush)
painter.fillRect(rect, self.bgColor)
else:
painter.fillRect(rect, self.background())
# Then overlay the texture
if self.useTexture:
# painter.fillRect(rect, self.backgroundBrush)
bgBrush = QBrush(self.bgTexture)
painter.fillRect(rect, bgBrush)
# Overlay the logo last
if self.useLogo:
if not len(self.subWindowList()): # Nothing is open.
cSizeW, cSizeH = rect.width(), rect.height()
bgLogoW, bgLogoH = self.bgLogo.width(), self.bgLogo.height()
if bgLogoW > cSizeW:
# Proportional Scaling an Image.
newHeight = bgLogoH * cSizeW // bgLogoW
scaledLogo = self.bgLogo.scaled(cSizeW, newHeight)
painter.drawPixmap(0,
cSizeH // 2 - scaledLogo.height() // 2,
scaledLogo)
else:
painter.drawPixmap((cSizeW - bgLogoW) // 2,
(cSizeH - bgLogoH) // 2,
self.bgLogo)
else:
# Center the pixmap
dx = (rect.width() - self.bgLogo.width()) / 2
dy = (rect.height() - self.bgLogo.height()) / 2
painter.drawPixmap(dx, dy,
self.bgLogo.width(), self.bgLogo.height(),
self.bgLogo)
示例13: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, event):
super().paintEvent(event)
painter = QPainter(self)
painter.fillRect(event.rect(), self.color)
示例14: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paintEvent(self, event):
p = QPainter()
p.begin(self)
p.fillRect(self.rect(), QBrush(QColor(240, 200, 0)))
p.end()
示例15: paint_redock_overlay
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import fillRect [as 别名]
def paint_redock_overlay(widget):
painter = QPainter(widget)
brush = QBrush(QApplication.palette().color(QPalette.Highlight),
Qt.Dense6Pattern)
painter.fillRect(widget.rect(), brush)