本文整理汇总了Python中python_qt_binding.QtGui.QWidget.paintEvent方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.paintEvent方法的具体用法?Python QWidget.paintEvent怎么用?Python QWidget.paintEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类python_qt_binding.QtGui.QWidget
的用法示例。
在下文中一共展示了QWidget.paintEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import paintEvent [as 别名]
def paintEvent(self, event):
contents_y = self.edit.verticalScrollBar().value()
page_bottom = contents_y + self.edit.viewport().height()
font_metrics = self.fontMetrics()
current_block = self.edit.document().findBlock(self.edit.textCursor().position())
painter = QPainter(self)
painter.setPen(Qt.darkGray)
line_count = 0
# Iterate over all text blocks in the document.
block = self.edit.document().begin()
while block.isValid():
line_count += 1
# the top left position of the block in the document
position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
# check if the position of the block is out side of visible area
if position.y() > page_bottom:
break
# we want the line number for the selected line to be bold.
bold = False
if block == current_block:
bold = True
font = painter.font()
font.setBold(True)
painter.setFont(font)
painter.setPen(Qt.black)
# Draw the line number right justified at the y position of the
# line. 3 is the magic padding number. drawText(x, y, text)
painter.drawText(
self.width() - font_metrics.width(str(line_count)) - 3,
round(position.y()) - contents_y + font_metrics.ascent() + self.edit.document().documentMargin(),
str(line_count),
)
if bold:
font = painter.font()
font.setBold(False)
painter.setFont(font)
painter.setPen(Qt.darkGray)
block = block.next()
self.highest_line = line_count
painter.end()
QWidget.paintEvent(self, event)