本文整理汇总了Python中PyQt5.Qt.QPainter.fillRect方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.fillRect方法的具体用法?Python QPainter.fillRect怎么用?Python QPainter.fillRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPainter
的用法示例。
在下文中一共展示了QPainter.fillRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def save(self, filename, chart_size, legend_width=None):
""" save graph as file
"""
if not filename:
""" if filename is not specified, open a save file dialog
"""
filename = QFileDialog.getSaveFileName(None, 'Save File')[0]
if not filename[-4:] in ['.png', '.jpg',]:
""" TODO : cleaner extension manager
"""
filename += ".png"
image_size = chart_size
if legend_width:
image_size = image_size + QSize(legend_width, 0)
image = QImage(image_size, QImage.Format_ARGB32_Premultiplied)
painter = QPainter(image)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(image.rect(), Qt.white)
self.draw(painter, QRect(QPoint(0, 0), chart_size))
if legend_width:
legendRect = QRect(QPoint(chart_size.width(), 10),
QSize(legend_width, chart_size.height()))
self.draw_legend(painter, legendRect)
painter.end()
return image.save(filename)
示例2: paint_line_numbers
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paint_line_numbers(self, ev):
painter = QPainter(self.line_number_area)
painter.fillRect(ev.rect(), self.line_number_palette.color(QPalette.Base))
block = self.firstVisibleBlock()
num = block.blockNumber()
top = int(self.blockBoundingGeometry(block).translated(self.contentOffset()).top())
bottom = top + int(self.blockBoundingRect(block).height())
current = self.textCursor().block().blockNumber()
painter.setPen(self.line_number_palette.color(QPalette.Text))
while block.isValid() and top <= ev.rect().bottom():
if block.isVisible() and bottom >= ev.rect().top():
if current == num:
painter.save()
painter.setPen(self.line_number_palette.color(QPalette.BrightText))
f = QFont(self.font())
f.setBold(True)
painter.setFont(f)
self.last_current_lnum = (top, bottom - top)
painter.drawText(
0, top, self.line_number_area.width() - 5, self.fontMetrics().height(), Qt.AlignRight, str(num + 1)
)
if current == num:
painter.restore()
block = block.next()
top = bottom
bottom = top + int(self.blockBoundingRect(block).height())
num += 1
示例3: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, event):
canvas_size = self.rect()
width = self.current_pixmap_size.width()
extrax = canvas_size.width() - width
if extrax < 0:
extrax = 0
x = int(extrax/2.)
height = self.current_pixmap_size.height()
extray = canvas_size.height() - height
if extray < 0:
extray = 0
y = int(extray/2.)
target = QRect(x, y, width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
spmap = self.pixmap.scaled(target.size() * dpr, Qt.KeepAspectRatio, Qt.SmoothTransformation)
spmap.setDevicePixelRatio(dpr)
p.drawPixmap(target, spmap)
if gprefs['bd_overlay_cover_size']:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
示例4: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, ev):
p = QPainter(self)
c = color('tab tree background', None)
if c:
p.fillRect(ev.rect(), QColor(c))
p.end()
QWidget.paintEvent(self, ev)
示例5: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, ev):
if self._animated_size < 1.0:
rect = self.rect()
painter = QPainter(self)
pal = self.palette()
col = pal.color(pal.Button)
rect.setLeft(rect.left() + (rect.width() * self._animated_size))
painter.setClipRect(rect)
painter.fillRect(self.rect(), col)
示例6: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, event):
w = self.viewport().rect().width()
painter = QPainter(self.viewport())
painter.setClipRect(event.rect())
floor = event.rect().bottom()
ceiling = event.rect().top()
fv = self.firstVisibleBlock().blockNumber()
origin = self.contentOffset()
doc = self.document()
lines = []
for num, text in self.headers:
top, bot = num, num + 3
if bot < fv:
continue
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y()
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y()
if max(y_top, y_bot) < ceiling:
continue
if min(y_top, y_bot) > floor:
break
painter.setFont(self.heading_font)
br = painter.drawText(3, y_top, w, y_bot - y_top - 5, Qt.TextSingleLine, text)
painter.setPen(QPen(self.palette().text(), 2))
painter.drawLine(0, br.bottom()+3, w, br.bottom()+3)
for top, bot, kind in self.changes:
if bot < fv:
continue
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y()
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y()
if max(y_top, y_bot) < ceiling:
continue
if min(y_top, y_bot) > floor:
break
if y_top != y_bot:
painter.fillRect(0, y_top, w, y_bot - y_top, self.diff_backgrounds[kind])
lines.append((y_top, y_bot, kind))
if top in self.images:
img, maxw = self.images[top][:2]
if bot > top + 1 and not img.isNull():
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top+1)).translated(origin).y() + 3
y_bot -= 3
scaled, imgw, imgh = fit_image(img.width(), img.height(), w - 3, y_bot - y_top)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
painter.drawPixmap(QRect(3, y_top, imgw, imgh), img)
painter.end()
PlainTextEdit.paintEvent(self, event)
painter = QPainter(self.viewport())
painter.setClipRect(event.rect())
for top, bottom, kind in sorted(lines, key=lambda (t, b, k):{'replace':0}.get(k, 1)):
painter.setPen(QPen(self.diff_foregrounds[kind], 1))
painter.drawLine(0, top, w, top)
painter.drawLine(0, bottom - 1, w, bottom - 1)
示例7: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, ev):
p = QPainter(self)
p.setClipRect(ev.rect())
bg = self.palette().color(QPalette.AlternateBase)
if self.hovering:
bg = bg.lighter(115)
p.fillRect(self.rect(), bg)
try:
p.drawText(self.rect(), Qt.AlignLeft|Qt.AlignVCenter|Qt.TextSingleLine, self.rendered_text)
finally:
p.end()
示例8: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, ev):
br = ev.region().boundingRect()
p = QPainter(self)
p.setOpacity(0.2)
p.fillRect(br, QBrush(self.palette().text()))
p.end()
QWidget.paintEvent(self, ev)
p = QPainter(self)
p.setClipRect(br)
f = p.font()
f.setBold(True)
f.setPointSize(20)
p.setFont(f)
p.setPen(Qt.SolidLine)
r = QRect(0, self.dummy.geometry().top() + 10, self.geometry().width(), 150)
p.drawText(r, Qt.AlignHCenter | Qt.AlignTop | Qt.TextSingleLine, self.text)
p.end()
示例9: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, ev):
painter = QPainter(self)
painter.setClipRect(ev.rect())
pal = self.palette()
painter.fillRect(self.rect(), pal.color(pal.Base))
painter.setFont(self.parent().font())
painter.setPen(QPen(pal.color(pal.Text)))
width = self.rect().width()
for i, st, y, height in self.iter_visible_items():
painter.save()
if i == self.current_index:
painter.fillRect(0, y, width, height, pal.color(pal.Highlight))
painter.setPen(QPen(pal.color(pal.HighlightedText)))
painter.drawStaticText(0, y, st)
painter.restore()
painter.end()
if self.current_size_hint is None:
QTimer.singleShot(0, self.layout)
示例10: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, ev):
if not self.static_text or not self.static_text.text():
return
p = QPainter(self)
p.setRenderHint(p.TextAntialiasing)
# If text is too long too fit, fade it out at the end
self.static_text.setTextWidth(self.rect().width())
sz = self.static_text.size()
r = self.rect()
p.drawStaticText(0, (r.height() - sz.height()) // 2, self.static_text)
if sz.width() > r.width():
g = QLinearGradient(self.rect().topLeft(), self.rect().topRight())
c = QColor(self.sb_background)
c.setAlpha(0)
g.setColorAt(0, c)
g.setColorAt(0.8, c)
g.setColorAt(1.0, self.sb_background)
p.fillRect(self.rect(), QBrush(g))
p.end()
示例11: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, event):
pmap = self.blank if self.pixmap is None or self.pixmap.isNull() else self.pixmap
target = self.rect()
scaled, width, height = fit_image(pmap.width(), pmap.height(), target.width(), target.height())
target.setRect(target.x(), target.y(), width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, pmap)
if self.pixmap is not None and not self.pixmap.isNull():
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
示例12: drag_icon
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def drag_icon(self, cover, multiple):
cover = cover.scaledToHeight(120, Qt.SmoothTransformation)
if multiple:
base_width = cover.width()
base_height = cover.height()
base = QImage(base_width+21, base_height+21,
QImage.Format_ARGB32_Premultiplied)
base.fill(QColor(255, 255, 255, 0).rgba())
p = QPainter(base)
rect = QRect(20, 0, base_width, base_height)
p.fillRect(rect, QColor('white'))
p.drawRect(rect)
rect.moveLeft(10)
rect.moveTop(10)
p.fillRect(rect, QColor('white'))
p.drawRect(rect)
rect.moveLeft(0)
rect.moveTop(20)
p.fillRect(rect, QColor('white'))
p.save()
p.setCompositionMode(p.CompositionMode_SourceAtop)
p.drawImage(rect.topLeft(), cover)
p.restore()
p.drawRect(rect)
p.end()
cover = base
return QPixmap.fromImage(cover)
示例13: paint_line_numbers
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paint_line_numbers(self, ev):
painter = QPainter(self.line_number_area)
painter.fillRect(ev.rect(), self.line_number_palette.color(QPalette.Base))
block = self.firstVisibleBlock()
num = block.blockNumber()
top = int(self.blockBoundingGeometry(block).translated(self.contentOffset()).top())
bottom = top + int(self.blockBoundingRect(block).height())
painter.setPen(self.line_number_palette.color(QPalette.Text))
change_starts = {x[0] for x in self.changes}
while block.isValid() and top <= ev.rect().bottom():
r = ev.rect()
if block.isVisible() and bottom >= r.top():
text = unicode(self.line_number_map.get(num, ''))
is_start = text != '-' and num in change_starts
if is_start:
painter.save()
f = QFont(self.font())
f.setBold(True)
painter.setFont(f)
painter.setPen(self.line_number_palette.color(QPalette.BrightText))
if text == '-':
painter.drawLine(r.left() + 2, (top + bottom)//2, r.right() - 2, (top + bottom)//2)
else:
if self.right:
painter.drawText(r.left() + 3, top, r.right(), self.fontMetrics().height(),
Qt.AlignLeft, text)
else:
painter.drawText(r.left() + 2, top, r.right() - 5, self.fontMetrics().height(),
Qt.AlignRight, text)
if is_start:
painter.restore()
block = block.next()
top = bottom
bottom = top + int(self.blockBoundingRect(block).height())
num += 1
示例14: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, event):
QWidget.paintEvent(self, event)
pmap = self._pixmap
if pmap.isNull():
return
w, h = pmap.width(), pmap.height()
ow, oh = w, h
cw, ch = self.rect().width(), self.rect().height()
scaled, nw, nh = fit_image(w, h, cw, ch)
if scaled:
pmap = pmap.scaled(int(nw*pmap.devicePixelRatio()), int(nh*pmap.devicePixelRatio()), Qt.IgnoreAspectRatio,
Qt.SmoothTransformation)
w, h = int(pmap.width()/pmap.devicePixelRatio()), int(pmap.height()/pmap.devicePixelRatio())
x = int(abs(cw - w)/2.)
y = int(abs(ch - h)/2.)
target = QRect(x, y, w, h)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, pmap)
if self.draw_border:
pen = QPen()
pen.setWidth(self.BORDER_WIDTH)
p.setPen(pen)
p.drawRect(target)
if self.show_size:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(ow, oh)
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
示例15: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import fillRect [as 别名]
def paintEvent(self, ev):
painter = QPainter(self)
painter.setClipRect(ev.rect())
pal = self.palette()
painter.fillRect(self.rect(), pal.color(pal.Text))
crect = self.rect().adjusted(1, 1, -1, -1)
painter.fillRect(crect, pal.color(pal.Base))
painter.setClipRect(crect)
painter.setFont(self.parent().font())
width = self.rect().width()
for i, st, y, height in self.iter_visible_items():
painter.save()
if i == self.current_index:
painter.fillRect(1, y, width, height, pal.color(pal.Highlight))
color = pal.color(QPalette.HighlightedText).name()
st = QStaticText(st)
text = st.text().partition('>')[2]
st.setText('<span style="color: %s">%s' % (color, text))
painter.drawStaticText(self.SIDE_MARGIN, y, st)
painter.restore()
painter.end()
if self.current_size_hint is None:
QTimer.singleShot(0, self.layout)