当前位置: 首页>>代码示例>>Python>>正文


Python QPainter.setClipRect方法代码示例

本文整理汇总了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)
开发者ID:auspex,项目名称:calibre,代码行数:11,代码来源:bars.py

示例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)
开发者ID:AtulKumar2,项目名称:calibre,代码行数:57,代码来源:view.py

示例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()
开发者ID:JimmXinu,项目名称:calibre,代码行数:13,代码来源:live_css.py

示例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()
开发者ID:nospy,项目名称:calibre,代码行数:15,代码来源:main.py

示例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)
开发者ID:AtulKumar2,项目名称:calibre,代码行数:20,代码来源:popup.py

示例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)
开发者ID:JimmXinu,项目名称:calibre,代码行数:25,代码来源:popup.py


注:本文中的PyQt5.Qt.QPainter.setClipRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。