def penMoveEvent(self, pos, pressure, liftedDeque): pen_x = pos[0] pen_y = pos[1] pen_pressure = pressure # print(liftedDeque) # print(self.__lastPos) if self.__lastPos is None: self.__lastPos = QPoint(pen_x, pen_y) self.__currentPos = QPoint(pen_x, pen_y) self.__painter.begin(self.__board) if self.EraserMode == False: #Non-Eraser mode self.__penColor = QColor("blue") self.__painter.setPen(QPen( self.__penColor, self.__thickness)) #Set pen color, thickness else: #Eraser mode: pen color is white, thickness is 6 self.__painter.setPen(QPen(Qt.white, 6)) self.__painter.drawLine(self.__lastPos, self.__currentPos) self.__painter.end() self.__lastPos = self.__currentPos self.update() #Show updates # If ever detected the pen is lifted, reset the __lastPos variable in order to reposition the pen if (True in liftedDeque): self.__lastPos = None
def penMoveEvent(self, pos, pressure): pen_x = pos[0] pen_y = pos[1] pen_pressure = pressure if self.__lastPos is None: self.__lastPos = QPoint(pen_x, pen_y) elif (abs(pen_x - self.__lastPos.x()) > 21 or abs(pen_y - self.__lastPos.y()) > 21): self.__lastPos = QPoint(pen_x, pen_y) self.__currentPos = QPoint(pen_x, pen_y) self.__painter.begin(self.__board) if self.EraserMode == False: #Non-Eraser mode self.__painter.setPen(QPen( self.__penColor, self.__thickness)) #Set pen color, thickness else: #Eraser mode: pen color is white, thickness is 6 self.__painter.setPen(QPen(Qt.white, 6)) self.__painter.drawLine(self.__lastPos, self.__currentPos) self.__painter.end() self.__lastPos = self.__currentPos self.update() #Show updates
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()
def paint_non_printing(self, painter, option, charcode): text = self.np_pat.sub(r'\n\1', non_printing[charcode]) painter.drawText( option.rect, Qt.AlignCenter | Qt.TextWordWrap | Qt.TextWrapAnywhere, text) painter.setPen(QPen(Qt.DashLine)) painter.drawRect(option.rect.adjusted(1, 1, -1, -1))
def paintEvent(self, event): QWidget.paintEvent(self, event) pmap = self._pixmap if pmap.isNull(): return w, h = pmap.width(), pmap.height() cw, ch = self.rect().width(), self.rect().height() scaled, nw, nh = fit_image(w, h, cw, ch) if scaled: pmap = pmap.scaled(nw, nh, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) w, h = pmap.width(), pmap.height() 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) pen = QPen() pen.setWidth(self.BORDER_WIDTH) p.setPen(pen) if self.draw_border: p.drawRect(target) #p.drawRect(self.rect()) p.end()
def drawScaleContents(self, painter, center, radius): dir = 90 #360 - int(roud(self.origin() - self.value())) arc = 90 #+ int(round(self.gradient * 90)) skyColor = QColor(38, 151, 221) painter.save() painter.setBrush(skyColor) painter.drawChord(self.scaleContentsRect(), (dir - arc) * 16, 2 * arc * 16) direction1 = self.value() * M_PI / 180.0 direction2 = self.value() * M_PI / 180.0 + M_PI_2 triangleSize = qRound(radius * 0.15) p0 = (QPoint(center.x() + 0, center.y() + 0)) p1 = qwtPolar2Pos(p0, 2, direction2) pa = QPolygon(3) pa.setPoint(0, qwtPolar2Pos(p1, 2 * triangleSize, direction2)) pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction2 + M_PI_2)) pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction2 - M_PI_2)) color = self.palette().color(QPalette.Text) painter.setBrush(color) painter.drawPolygon(pa) p0 = (QPoint(center.x() + 0, center.y() + 0)) color = self.palette().color(QPalette.Text) painter.setBrush(color) painter.setPen(QPen(color, 3)) painter.drawLine(qwtPolar2Pos(p0, radius - 3, direction1), qwtPolar2Pos(p0, radius - 3, direction1 - M_PI)) painter.restore()
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) p.drawPixmap( target, self.pixmap.scaled(target.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) 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()
def __init__(self, spurset, fef, parent): chart.__init__(self, spurset, fef, parent) self.plot = QwtPlot(parent) self.plot.setAxisScale(xaxis, self.spurset.RFmin, self.spurset.RFmax) self.plot.setAxisScale(yaxis, -self.spurset.dspan / 2, self.spurset.dspan / 2) self.plot.setCanvasBackground(Qt.white) grid = QwtPlotGrid() grid.setMajPen(QPen(Qt.black, 1, Qt.DotLine)) grid.attach(self.plot) self.plot.insertLegend(QwtLegend(self.parent), QwtPlot.ExternalLegend) # a picker to be used for the front-end filter parallelogram self.picker = QwtPlotPicker(xaxis, yaxis, QwtPicker.PointSelection, QwtPlotPicker.NoRubberBand, QwtPicker.AlwaysOff, self.plot.canvas()) # gonna need this to implement ondrop() self._mouseRelease = self.picker.widgetMouseReleaseEvent self._picked_obj = None self.picker.connect(self.picker, SIGNAL('appended(const QPoint&)'), self.onpick) self.picker.connect(self.picker, SIGNAL('moved(const QPoint&)'), self.ondrag) # all about the monkey-patching self.picker.widgetMouseReleaseEvent = self.ondrop
def paintArc(self, center_x, center_y, start_x, start_y, end_x, end_y): radius = math.sqrt( math.pow(center_x - start_x, 2) + math.pow(center_y - start_y, 2)) rect = QRectF(center_x - radius, center_y - radius, radius * 2, radius * 2) # start angle calculation startAngle = math.degrees( math.atan2(center_y - start_y, start_x - center_x)) # end angle calculation endAngle = math.degrees(math.atan2(center_y - end_y, end_x - center_x)) # span angle calculation spanAngle = endAngle - startAngle # assume user always wants to draw clock-wise if spanAngle > 0: spanAngle = -1 * (360 - spanAngle) #print("start angle is " + str(startAngle)) #print("span angle is " + str(spanAngle)) self.__painter.begin(self.__board) self.__penColor = QColor("black") self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawArc(rect, 16 * startAngle, 16 * spanAngle) self.__painter.end() self.update() #Show updates
def paintPolyg(self, x1, y1, x2, y2, x3, y3, x4, y4): self.__painter.begin(self.__board) self.__penColor = QColor("black") self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawPolygon(QPoint(x1, y1), QPoint(x2, y2), QPoint(x3, y3), QPoint(x4, y4)) self.__painter.end() self.update() #Show updates
def paintTriangle(self, points): self.__painter.begin(self.__board) self.__penColor = QColor("black") self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawPolygon(points) self.__painter.end() self.update() #Show updates
def __init__(self, plot, label, color="green", mode=QwtPicker.PointSelection, rubber_band=QwtPicker.VLineRubberBand, tracker_mode=QwtPicker.ActiveOnly, track=None): QwtPlotPicker.__init__(self, QwtPlot.xBottom, QwtPlot.yRight, mode, rubber_band, tracker_mode, plot.canvas()) self.plot = plot self.label = label self.track = track self.color = QColor(color) self.setRubberBandPen(QPen(self.color))
def paintEllipse(self, center_x, center_y, radias1, radias2): self.__painter.begin(self.__board) self.__penColor = QColor("black") self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawEllipse(QPoint(center_x, center_y), radias1, radias2) self.__painter.end() self.update() #Show updates
def paintLine(self, P1_x, P1_y, P2_x, P2_y): P1 = QPoint(P1_x, P1_y) P2 = QPoint(P2_x, P2_y) self.__painter.begin(self.__board) self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawLine(P1, P2) self.__painter.end() self.update() #Show updates
def __init__(self): self.fill = QBrush(Qt.white) self.stroke = QPen() self.opacity = 1.0 self.transform = QTransform() self.brush_origin = QPointF() self.clip_updated = False self.do_fill = False self.do_stroke = True self.qt_pattern_cache = {}
def copy(self): ans = GraphicsState() ans.fill = QBrush(self.fill) ans.stroke = QPen(self.stroke) ans.opacity = self.opacity ans.transform = self.transform * QTransform() ans.brush_origin = QPointF(self.brush_origin) ans.clip_updated = self.clip_updated ans.do_fill, ans.do_stroke = self.do_fill, self.do_stroke return ans
def paintRect(self, center_x, center_y, upper_left_x, upper_left_y): width = abs(2 * (center_x - upper_left_x)) height = abs(2 * (center_y - upper_left_y)) self.__painter.begin(self.__board) self.__penColor = QColor("black") self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawRect(upper_left_x, upper_left_y, width, height) self.__painter.end() self.update() #Show updates
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(nw, nh, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) w, h = pmap.width(), pmap.height() 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()
def paintArc(self, center_x, center_y, start_x, start_y, end_x, end_y): radius = math.sqrt( math.pow(center_x - start_x, 2) + math.pow(center_y - start_y, 2)) rect = QRectF(center_x - radius, center_y - radius, radius * 2, radius * 2) startAngle = 16 * math.atan2(start_x - center_y, start_x - center_x) * 180.0 / math.pi endAngle = 16 * math.atan2(end_y - center_y, end_x - center_x) * 180.0 / math.pi spanAngle = endAngle - startAngle self.__painter.begin(self.__board) self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawArc(rect, startAngle, spanAngle) self.__painter.end() self.update() #Show updates
def draw(self, painter, center, length, direction, cg): direction1 = direction * M_PI / 180.0 triangleSize = qRound(length * 0.1) painter.save() p0 = (QPoint(center.x() + 0, center.y() + 0)) p1 = qwtPolar2Pos(p0, length - 2 * triangleSize - 2, direction1) pa = QPolygon(3) pa.setPoint(0, qwtPolar2Pos(p1, 2 * triangleSize, direction1)) pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction1 + M_PI_2)) pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction1 - M_PI_2)) color = self.palette().color(cg, QPalette.Text) painter.setBrush(color) painter.drawPolygon(pa) painter.setPen(QPen(color, 3)) painter.drawLine(qwtPolar2Pos(p0, length - 2, direction1 + M_PI_2), qwtPolar2Pos(p0, length - 2, direction1 - M_PI_2)) painter.restore()
def addPlotBorder(self, border_pen, label, label_color=None, bg_brush=None): # make plot items for image frame # make curve for image borders (l0, l1), (m0, m1) = self.image.getExtents() self._border_pen = QPen(border_pen) self._image_border.show() self._image_border.setData([l0, l0, l1, l1, l0], [m0, m1, m1, m0, m0]) self._image_border.setPen(self._border_pen) self._image_border.setZ(self.image.z() + 1 if self._z_markers is None else self._z_markers) if label: self._image_label.show() self._image_label_text = text = QwtText(" %s " % label) text.setColor(label_color) text.setBackgroundBrush(bg_brush) self._image_label.setValue(l1, m1) self._image_label.setLabel(text) self._image_label.setLabelAlignment(Qt.AlignRight | Qt.AlignVCenter) self._image_label.setZ(self.image.z() + 2 if self._z_markers is None else self._z_markers)
def paintEvent(self, event): res = QToolButton.paintEvent(self, event) if _enable_hacked_QToolButton_paintEvent and self.isChecked(): r = event.rect() x,y = r.left(), r.top() w,h = r.width(), r.height() # There are at least three rect sizes: 30x35, 30x36, 32x33 (see debug-print below). # Not sure if this sometimes includes some padding around the icon. ## print r.top(),r.bottom(),r.height(), r.left(),r.right(),r.width() ## 0 29 30 0 34 35 ## 0 29 30 0 35 36 ## 0 31 32 0 32 33 p = QPainter(self, True) # True claims to mean un-clipped -- not sure if this is good. ## Qt4 error: TypeError: too many arguments to QPainter(), 1 at most expected color = toolbutton_highlight_color p.setPen(QPen(color, 3)) # try 3 and 2 p.drawRect(x+2,y+2,w-4,h-4) #e could also try drawRoundRect(r, xroundedness, yroundedness) return res
def paintBezierSpline(self, pointListX, pointListY): P1 = QPoint(int(pointListX[0]), int(pointListY[0])) path = QtGui.QPainterPath() path.moveTo(P1) self.__painter.begin(self.__board) self.__painter.setPen(QPen(self.__penColor, self.__thickness)) i = 0 while i < len(pointListX) - 3: P2 = QPoint(int(pointListX[i + 1]), int(pointListY[i + 1])) P3 = QPoint(int(pointListX[i + 2]), int(pointListY[i + 2])) P4 = QPoint(int(pointListX[i + 3]), int(pointListY[i + 3])) path.cubicTo(P2, P3, P4) self.__painter.drawPath(path) i += 3 self.__painter.end() self.update() #Show updates
def failed_img(self): if self._failed_img is None: i = QImage(200, 150, QImage.Format_ARGB32) i.fill(Qt.white) p = QPainter(i) r = i.rect().adjusted(10, 10, -10, -10) n = QPen(Qt.DashLine) n.setColor(Qt.black) p.setPen(n) p.drawRect(r) p.setPen(Qt.black) f = self.font() f.setPixelSize(20) p.setFont(f) p.drawText(r.adjusted(10, 0, -10, 0), Qt.AlignCenter | Qt.TextWordWrap, _('Image could not be rendered')) p.end() self._failed_img = QPixmap.fromImage(i) return self._failed_img
def paintAuxArc(self, center_x, center_y, start_x, start_y, end_x, end_y): radius = math.sqrt( math.pow(center_x - start_x, 2) + math.pow(center_y - start_y, 2)) rect = QRectF(center_x - radius, center_y - radius, radius * 2, radius * 2) # start angle calculation startAngle = math.degrees( math.atan2(center_y - start_y, start_x - center_x)) # end angle calculation endAngle = math.degrees(math.atan2(center_y - end_y, end_x - center_x)) # span angle calculation spanAngle = 0 if (self._isAngleInThirdQuadrant(startAngle) and self._isAngleInSecondQuadrant(endAngle) ) or (self._isAngleInThirdQuadrant(endAngle) and self._isAngleInSecondQuadrant(startAngle)) or ( startAngle == 180 and self._isAngleInThirdQuadrant(endAngle) ) or (startAngle == -180 and self._isAngleInSecondQuadrant(endAngle)) or ( endAngle == 180 and self._isAngleInThirdQuadrant(startAngle)) or ( endAngle == -180 and self._isAngleInSecondQuadrant(startAngle)): if startAngle == 180 or self._isAngleInThirdQuadrant(startAngle): spanAngle = endAngle - (startAngle + 360) else: spanAngle = (endAngle + 360) - startAngle else: spanAngle = endAngle - startAngle #print("start angle is " + str(startAngle)) #print("span angle is " + str(spanAngle)) self.__painter.begin(self.__board) self.__penColor = QColor("red") self.__painter.setPen(QPen(self.__penColor, self.__thickness)) self.__painter.drawArc(rect, 16 * startAngle, 16 * spanAngle) self.__painter.end() self.update() #Show updates
def __init__(self, plot, color="black", linestyle=Qt.DotLine, align=Qt.AlignBottom | Qt.AlignRight, z=90, label="", zlabel=None, linewidth=1, spacing=2, yaxis=QwtPlot.yRight): self.line = TiggerPlotCurve() self.color = color = color if isinstance(color, QColor) else QColor(color) self.line.setPen(QPen(color, linewidth, linestyle)) self.marker = TiggerPlotMarker() self.marker.setLabelAlignment(align) try: self.marker.setSpacing(spacing) except AttributeError: pass self.setText(label) self.line.setZ(z) self.marker.setZ(zlabel if zlabel is not None else z) # set axes -- using yRight, since that is the "markup" z-axis self.line.setAxis(QwtPlot.xBottom, yaxis) self.marker.setAxis(QwtPlot.xBottom, yaxis) # attach to plot self.line.attach(plot) self.marker.attach(plot)
def background(painter, bkgimg): maxx = painter.device().width() maxy = painter.device().height() rimg = QRectF(0, 0, maxx, maxy * .9) # painter.fillRect(0, 0, maxx, maxy, QBrush(Qt.red, Qt.SolidPattern)) painter.drawImage(rimg, bkgimg) wwh = QColor(255, 255, 255, 128) painter.fillRect(0, 2 * maxy / 10, maxx, 4 * maxy / 10, QBrush(wwh, Qt.SolidPattern)) u = QRectF(0, 9 * maxy / 10, maxx, maxy / 10) penHText = QPen(Qt.white) painter.setPen(penHText) painter.setFont(QFont("Arial", 16, italic=True)) painter.drawText( u, Qt.AlignLeft | Qt.TextIncludeTrailingSpaces | Qt.AlignVCenter, " ekskursja.pl/flashcards")
def paintPCircle(self, center_x, center_y, start_x, start_y, pers_x, pers_y): point = [start_x, start_y] center = [center_x, center_y] distance = [(point[0] - center[0]), (point[1] - center[1])] phi = math.atan2(distance[1], distance[0]) r = math.sqrt(distance[0] * distance[0] + distance[1] * distance[1]) points = self.PointsInCircum(r, 300, phi) #Drawing the circle in perspective dist_x = center_x - pers_x print("dist_x", dist_x, pers_x, pers_y, center_x, center_y) points = [(j[0], (j[1] + center_x - pers_y) * ((j[0] + center_x) / dist_x) + pers_y - center_y) for j in points] self.__painter.begin(self.__board) self.__penColor = QColor("blue") self.__painter.setPen(QPen(self.__penColor, self.__thickness)) for x in points: self.__painter.drawPoint(round(x[0] + center[0], 3), round(x[1] / 1.00 + center[1], 3)) self.__painter.end()
def do_paint(self, painter, option, index): text = unicode(index.data(Qt.DisplayRole).toString()) font = QFont(option.font) font.setPointSize(QFontInfo(font).pointSize() * 1.5) font2 = QFont(font) font2.setFamily(text) system, has_latin = writing_system_for_font(font2) if has_latin: font = font2 r = option.rect if option.state & QStyle.State_Selected: painter.setPen(QPen(option.palette.highlightedText(), 0)) if (option.direction == Qt.RightToLeft): r.setRight(r.right() - 4) else: r.setLeft(r.left() + 4) painter.setFont(font) painter.drawText(r, Qt.AlignVCenter | Qt.AlignLeading | Qt.TextSingleLine, text) if (system != QFontDatabase.Any): w = painter.fontMetrics().width(text + " ") painter.setFont(font2) sample = QFontDatabase().writingSystemSample(system) if (option.direction == Qt.RightToLeft): r.setRight(r.right() - w) else: r.setLeft(r.left() + w) painter.drawText( r, Qt.AlignVCenter | Qt.AlignLeading | Qt.TextSingleLine, sample)
def paintEvent(self, event): QSplitterHandle.paintEvent(self, event) left, right = self.parent().left, self.parent().right painter = QPainter(self) painter.setClipRect(event.rect()) w = self.width() h = self.height() painter.setRenderHints(QPainter.Antialiasing, True) C = 16 # Curve factor. def create_line(ly, ry, right_to_left=False): ' Create path that represents upper or lower line of change marker ' line = QPainterPath() if not right_to_left: line.moveTo(0, ly) line.cubicTo(C, ly, w - C, ry, w, ry) else: line.moveTo(w, ry) line.cubicTo(w - C, ry, C, ly, 0, ly) return line ldoc, rdoc = left.document(), right.document() lorigin, rorigin = left.contentOffset(), right.contentOffset() lfv, rfv = left.firstVisibleBlock().blockNumber( ), right.firstVisibleBlock().blockNumber() lines = [] for (ltop, lbot, kind), (rtop, rbot, kind) in zip(left.changes, right.changes): if lbot < lfv and rbot < rfv: continue ly_top = left.blockBoundingGeometry( ldoc.findBlockByNumber(ltop)).translated(lorigin).y() ly_bot = left.blockBoundingGeometry( ldoc.findBlockByNumber(lbot)).translated(lorigin).y() ry_top = right.blockBoundingGeometry( rdoc.findBlockByNumber(rtop)).translated(rorigin).y() ry_bot = right.blockBoundingGeometry( rdoc.findBlockByNumber(rbot)).translated(rorigin).y() if max(ly_top, ly_bot, ry_top, ry_bot) < 0: continue if min(ly_top, ly_bot, ry_top, ry_bot) > h: break upper_line = create_line(ly_top, ry_top) lower_line = create_line(ly_bot, ry_bot, True) region = QPainterPath() region.moveTo(0, ly_top) region.connectPath(upper_line) region.lineTo(w, ry_bot) region.connectPath(lower_line) region.closeSubpath() painter.fillPath(region, left.diff_backgrounds[kind]) for path, aa in zip((upper_line, lower_line), (ly_top != ry_top, ly_bot != ry_bot)): lines.append((kind, path, aa)) for kind, path, aa in sorted( lines, key=lambda x: {'replace': 0}.get(x[0], 1)): painter.setPen(left.diff_foregrounds[kind]) painter.setRenderHints(QPainter.Antialiasing, aa) painter.drawPath(path) painter.setFont(left.heading_font) for (lnum, text), (rnum, text) in zip(left.headers, right.headers): ltop, lbot, rtop, rbot = lnum, lnum + 3, rnum, rnum + 3 if lbot < lfv and rbot < rfv: continue ly_top = left.blockBoundingGeometry( ldoc.findBlockByNumber(ltop)).translated(lorigin).y() ly_bot = left.blockBoundingGeometry( ldoc.findBlockByNumber(lbot)).translated(lorigin).y() ry_top = right.blockBoundingGeometry( rdoc.findBlockByNumber(rtop)).translated(rorigin).y() ry_bot = right.blockBoundingGeometry( rdoc.findBlockByNumber(rbot)).translated(rorigin).y() if max(ly_top, ly_bot, ry_top, ry_bot) < 0: continue if min(ly_top, ly_bot, ry_top, ry_bot) > h: break ly = painter.boundingRect(3, ly_top, left.width(), ly_bot - ly_top - 5, Qt.TextSingleLine, text).bottom() + 3 ry = painter.boundingRect(3, ry_top, right.width(), ry_bot - ry_top - 5, Qt.TextSingleLine, text).bottom() + 3 line = create_line(ly, ry) painter.setPen(QPen(left.palette().text(), 2)) painter.setRenderHints(QPainter.Antialiasing, ly != ry) painter.drawPath(line) painter.end() # Paint the splitter without the change lines if the mouse is over the # splitter if getattr(self, 'hover', False): QSplitterHandle.paintEvent(self, event)