本文整理汇总了Python中PyQt5.Qt.QPainter.setClipRect方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.setClipRect方法的具体用法?Python QPainter.setClipRect怎么用?Python QPainter.setClipRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPainter
的用法示例。
在下文中一共展示了QPainter.setClipRect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import setClipRect [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)
示例2: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import setClipRect [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)
示例3: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import setClipRect [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()
示例4: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import setClipRect [as 别名]
def paintEvent(self, ev):
br = ev.region().boundingRect()
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()
示例5: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import setClipRect [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)
示例6: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import setClipRect [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)