本文整理汇总了Python中PyQt5.Qt.QPainter.restore方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.restore方法的具体用法?Python QPainter.restore怎么用?Python QPainter.restore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPainter
的用法示例。
在下文中一共展示了QPainter.restore方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint_line_numbers
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [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
示例2: drag_icon
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [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)
示例3: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [as 别名]
def paintEvent(self, ev):
p = QPainter(self)
p.setClipRect(ev.rect())
palette = self.palette()
p.setPen(palette.color(QPalette.WindowText))
if not self.is_first:
p.drawLine(0, 0, self.width(), 0)
try:
for row in self.rows:
for cell in row:
p.save()
try:
cell.draw(p, self.width(), palette)
finally:
p.restore()
finally:
p.end()
示例4: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [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)
示例5: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [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)
示例6: paint_line_numbers
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [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
示例7: PDFWriter
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [as 别名]
#.........这里部分代码省略.........
if self.header and opts.margin_top < min_margin:
self.log.warn('Top margin is too small for header, increasing it to %.1fpts' % min_margin)
opts.margin_top = min_margin
self.page.setViewportSize(QSize(self.doc.width(), self.doc.height()))
self.render_queue = items
self.total_items = len(items)
mt, mb = map(self.doc.to_px, (opts.margin_top, opts.margin_bottom))
self.margin_top, self.margin_bottom = map(lambda x:int(floor(x)), (mt, mb))
self.painter = QPainter(self.doc)
self.doc.set_metadata(title=pdf_metadata.title,
author=pdf_metadata.author,
tags=pdf_metadata.tags, mi=pdf_metadata.mi)
self.doc_title = pdf_metadata.title
self.doc_author = pdf_metadata.author
self.painter.save()
try:
if self.cover_data is not None:
p = QPixmap()
try:
p.loadFromData(self.cover_data)
except TypeError:
self.log.warn('This ebook does not have a raster cover, cannot generate cover for PDF'
'. Cover type: %s' % type(self.cover_data))
if not p.isNull():
self.doc.init_page()
draw_image_page(QRect(*self.doc.full_page_rect),
self.painter, p,
preserve_aspect_ratio=self.opts.preserve_cover_aspect_ratio)
self.doc.end_page()
finally:
self.painter.restore()
QTimer.singleShot(0, self.render_book)
if self.loop.exec_() == 1:
raise Exception('PDF Output failed, see log for details')
if self.toc is not None and len(self.toc) > 0:
self.doc.add_outline(self.toc)
self.painter.end()
if self.doc.errors_occurred:
raise Exception('PDF Output failed, see log for details')
def render_inline_toc(self):
self.rendered_inline_toc = True
from calibre.ebooks.pdf.render.toc import toc_as_html
raw = toc_as_html(self.toc, self.doc, self.opts)
pt = PersistentTemporaryFile('_pdf_itoc.htm')
pt.write(raw)
pt.close()
self.render_queue.append(pt.name)
self.render_next()
def render_book(self):
if self.doc.errors_occurred:
return self.loop.exit(1)
try:
if not self.render_queue:
if self.opts.pdf_add_toc and self.toc is not None and len(self.toc) > 0 and not hasattr(self, 'rendered_inline_toc'):
return self.render_inline_toc()
self.loop.exit()
else:
示例8: PDFWriter
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import restore [as 别名]
#.........这里部分代码省略.........
self.page.setViewportSize(QSize(self.doc.width(), self.doc.height()))
self.render_queue = items
self.total_items = len(items)
mt, mb = map(self.doc.to_px, (mt, mb))
self.margin_top, self.margin_bottom = map(lambda x:int(floor(x)), (mt, mb))
self.painter = QPainter(self.doc)
try:
self.book_language = pdf_metadata.mi.languages[0]
except Exception:
self.book_language = 'eng'
self.doc.set_metadata(title=pdf_metadata.title,
author=pdf_metadata.author,
tags=pdf_metadata.tags, mi=pdf_metadata.mi)
self.doc_title = pdf_metadata.title
self.doc_author = pdf_metadata.author
self.painter.save()
try:
if self.cover_data is not None:
p = QPixmap()
try:
p.loadFromData(self.cover_data)
except TypeError:
self.log.warn('This ebook does not have a raster cover, cannot generate cover for PDF'
'. Cover type: %s' % type(self.cover_data))
if not p.isNull():
self.doc.init_page()
draw_image_page(QRect(*self.doc.full_page_rect),
self.painter, p,
preserve_aspect_ratio=self.opts.preserve_cover_aspect_ratio)
self.doc.end_page()
finally:
self.painter.restore()
QTimer.singleShot(0, self.render_book)
if self.loop.exec_() == 1:
raise Exception('PDF Output failed, see log for details')
if self.toc is not None and len(self.toc) > 0:
self.doc.add_outline(self.toc)
self.painter.end()
if self.doc.errors_occurred:
raise Exception('PDF Output failed, see log for details')
def render_inline_toc(self):
evaljs = self.view.page().mainFrame().evaluateJavaScript
self.rendered_inline_toc = True
from calibre.ebooks.pdf.render.toc import toc_as_html
raw = toc_as_html(self.toc, self.doc, self.opts, evaljs)
pt = PersistentTemporaryFile('_pdf_itoc.htm')
pt.write(raw)
pt.close()
self.render_queue.append(pt.name)
self.render_next()
def render_book(self):
if self.doc.errors_occurred:
return self.loop.exit(1)
try:
if not self.render_queue:
if self.opts.pdf_add_toc and self.toc is not None and len(self.toc) > 0 and not hasattr(self, 'rendered_inline_toc'):
return self.render_inline_toc()
self.loop.exit()