def paint(self, painter, option, widget): """Draws the code block""" del option del widget baseX = (self.__viewWidth - self.__rectWidth) / 2 baseY = (self.__viewHeight - self.__rectHeight) / 2 if self.__borderColor is None: pen = QPen(self.__bgColor) else: pen = QPen(self.__borderColor) painter.setPen(pen) brush = QBrush(self.__bgColor) painter.setBrush(brush) painter.drawRect(baseX, baseY, self.__rectWidth, self.__rectHeight) # Draw the text in the rectangle pen = QPen(self.__fgColor) painter.setFont(self.__settings.monoFont) painter.setPen(pen) textWidth = self.__textRect.width() + 2 * self.__settings.hTextPadding textShift = (self.__rectWidth - textWidth) / 2 painter.drawText(baseX + self.__settings.hTextPadding + textShift, baseY + self.__settings.vTextPadding, self.__textRect.width(), self.__textRect.height(), Qt.AlignLeft, 'Sample')
def paint(self, painter, option, widget): """Draws a curve and then adds an arrow""" pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) painter.setRenderHint(QPainter.Antialiasing, True) QGraphicsPathItem.paint(self, painter, option, widget)
def getPainterPen(self, selected, borderColor): """Provides the painter pen for the item""" if selected: pen = QPen(self.canvas.settings.selectColor) pen.setWidth(self.canvas.settings.selectPenWidth) else: pen = QPen(borderColor) pen.setWidth(self.canvas.settings.boxLineWidth) pen.setJoinStyle(Qt.RoundJoin) return pen
def __init__(self, node): QGraphicsRectItem.__init__(self) self.__node = node posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) self.setBrush(QColor(216, 216, 207))
def paint(self, painter, option, widget): """Paints the rubber band""" pen = QPen(self.__settings.rubberBandBorderColor) painter.setPen(pen) brush = QBrush(self.__settings.rubberBandFGColor) painter.setBrush(brush) painter.drawRect(self.__x, self.__y, self.__width, self.__height)
def paint(self, painter, option, widget): """Draws the import statement""" del option # unused argument del widget # unused argument settings = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) takenByBadges = self.aboveBadges.height + settings.badgeToScopeVPadding yPos = self.baseY + settings.vCellPadding + takenByBadges xPos = self.baseX + settings.hCellPadding rectWidth = self.minWidth - 2 * settings.hCellPadding rectHeight = self.minHeight - 2 * settings.vCellPadding - takenByBadges painter.drawRoundedRect(xPos, yPos, rectWidth, rectHeight, settings.decorRectRadius, settings.decorRectRadius) # Draw the text in the rectangle pen = QPen(self.fgColor) painter.setFont(settings.monoFont) painter.setPen(pen) painter.drawText( xPos + settings.hTextPadding, yPos + settings.vTextPadding, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)
def paint(self, painter, option, widget): """Draws the independent comment""" del option # unused argument del widget # unused argument settings = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) rectWidth = self.minWidth - 2 * settings.hCellPadding rectHeight = self.minHeight - 2 * settings.vCellPadding painter.drawRoundedRect(self.baseX + settings.hCellPadding, self.baseY + settings.vCellPadding, rectWidth, rectHeight, 0, 0) if self.text: # Draw the text in the rectangle font = QFont(settings.monoFont) font.setItalic(True) painter.setFont(font) pen = QPen(self.fgColor) painter.setPen(pen) painter.drawText( self._leftEdge + settings.hCellPadding + settings.hDocLinkPadding + self.iconItem.iconWidth() + settings.hDocLinkPadding, self.baseY + settings.vCellPadding + settings.vDocLinkPadding, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)
def __paintComment(self, painter): """Paints the side comment""" s = self.canvas.settings painter.setPen( self.getPainterPen(self.isSelected(), s.commentBorderColor)) painter.setBrush(QBrush(s.commentBGColor)) canvasTop = self.baseY - s.scopeRectRadius # s.vHeaderPadding below is used intentionally: to have the same # spacing on top, bottom and right for the comment box movedBaseX = self.canvas.baseX + self.canvas.minWidth - \ self.width - s.scopeRectRadius - s.vHeaderPadding if s.hidecomments: painter.drawRoundedRect( movedBaseX + s.hHeaderPadding, canvasTop + s.vHeaderPadding, self.iconItem.iconWidth() + 2 * s.hHiddenCommentPadding, self.iconItem.iconHeight() + 2 * s.vHiddenCommentPadding, s.hiddenCommentRectRadius, s.hiddenCommentRectRadius) else: painter.drawPath(self.__sideCommentPath) pen = QPen(s.commentFGColor) painter.setFont(s.monoFont) painter.setPen(pen) painter.drawText(movedBaseX + s.hHeaderPadding + s.hTextPadding, canvasTop + s.vHeaderPadding + s.vTextPadding, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)
def __init__(self, node, refFile, srcobj, deviceDPI): self.__node = node self.__srcobj = srcobj self.__refFile = refFile self.__pixelsPerLine = self.calcPixelsPerLine() posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) # To make double click delivered self.setFlag(QGraphicsItem.ItemIsSelectable, True)
def paintBadgeRectangle(self, painter, isSelected, borderColor, bgColor): """Draws the badge filled rectange""" s = self.ref.canvas.settings if isSelected: pen = QPen(s.selectColor) pen.setWidth(s.selectPenWidth) else: pen = QPen(borderColor) pen.setWidth(s.badgeLineWidth) pen.setJoinStyle(Qt.RoundJoin) painter.setPen(pen) painter.setBrush(QBrush(bgColor)) painter.drawRoundedRect(self.x(), self.y(), self.width, self.height, s.badgeRadius, s.badgeRadius)
def paint(self, painter, option, widget): """Draws a filled rectangle and then adds a title""" # Hide the dotted outline itemOption = QStyleOptionGraphicsItem(option) if itemOption.state & QStyle.State_Selected != 0: itemOption.state = itemOption.state & ~QStyle.State_Selected # Draw the rectangle pen = painter.pen() pen.setJoinStyle(Qt.RoundJoin) painter.setPen(pen) QGraphicsRectItem.paint(self, painter, itemOption, widget) # Draw text over the rectangle painter.setFont(self.__font) painter.setPen(QPen(QColor(255, 255, 255))) painter.drawText(self.__node.posX - self.__node.width / 2.0, self.__node.posY - self.__node.height / 2.0, self.__node.width, self.__node.height, Qt.AlignCenter, self.__node.label.replace('\\n', '\n')) if self.__outside: pixmap = getPixmap("nonprojectentrydgm.png") pixmapPosX = self.__node.posX - self.__node.width / 2.0 + 2 pixmapPosY = self.__node.posY + self.__node.height / 2.0 - \ pixmap.height() - 2 painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.drawPixmap(pixmapPosX, pixmapPosY, pixmap)
def paint(self, painter, option, widget): """Draws the code block""" del option # unused argument del widget # unused argument settings = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) rectWidth = self.minWidth - 2 * settings.hCellPadding rectHeight = self.minHeight - 2 * settings.vCellPadding yPos = self.baseY + settings.vCellPadding if self.aboveBadges.hasAny(): badgeShift = self.aboveBadges.height + settings.badgeToScopeVPadding yPos += badgeShift rectHeight -= badgeShift painter.drawRect(self.baseX + settings.hCellPadding, yPos, rectWidth, rectHeight) # Draw the text in the rectangle pen = QPen(self.fgColor) painter.setFont(settings.monoFont) painter.setPen(pen) textWidth = self.textRect.width() + 2 * settings.hTextPadding textShift = (rectWidth - textWidth) / 2 painter.drawText( self.baseX + settings.hCellPadding + settings.hTextPadding + textShift, yPos + settings.vTextPadding, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)
def paint(self, painter, option, widget): """Draws the code block""" del option # unused argument del widget # unused argument settings = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) painter.drawPolygon(QPointF(self.x1, self.y1), QPointF(self.x2, self.y2), QPointF(self.x3, self.y3), QPointF(self.x4, self.y4), QPointF(self.x5, self.y5), QPointF(self.x6, self.y6)) # Draw the text in the rectangle pen = QPen(self.fgColor) painter.setPen(pen) painter.setFont(settings.monoFont) availWidth = self.x3 - self.x2 textWidth = self.textRect.width() + 2 * settings.hTextPadding textShift = (availWidth - textWidth) / 2 painter.drawText( self.x2 + settings.hTextPadding + textShift, self.baseY + settings.vCellPadding + settings.vTextPadding, self.textRect.width(), self.textRect.height(), Qt.AlignLeft | Qt.AlignVCenter, self.text)
def paint(self, painter, option, widget): """Draws the import statement""" del option # unused argument del widget # unused argument settings = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) painter.drawRect(self.baseX + settings.hCellPadding, self.baseY + settings.vCellPadding, self.minWidth - 2 * settings.hCellPadding, self.minHeight - 2 * settings.vCellPadding) painter.drawLine( self.baseX + settings.hCellPadding + self.iconItem.iconWidth() + 2 * settings.hTextPadding, self.baseY + settings.vCellPadding, self.baseX + settings.hCellPadding + self.iconItem.iconWidth() + 2 * settings.hTextPadding, self.baseY + self.minHeight - settings.vCellPadding) # Draw the text in the rectangle pen = QPen(self.fgColor) painter.setFont(settings.monoFont) painter.setPen(pen) textRectWidth = self.minWidth - 2 * settings.hCellPadding - \ 4 * settings.hTextPadding - self.iconItem.iconWidth() textShift = (textRectWidth - self.textRect.width()) / 2 painter.drawText( self.baseX + settings.hCellPadding + self.iconItem.iconWidth() + 3 * settings.hTextPadding + textShift, self.baseY + settings.vCellPadding + settings.vTextPadding, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)
def paint(self, painter, option, widget): """Draws the leading comment""" settings = self.canvas.settings self.setPen( self.getPainterPen(self.isSelected(), settings.commentBorderColor)) self.setBrush(QBrush(settings.commentBGColor)) # Bottom adjustment yShift = self.height - self.minHeight baseY = self.baseY + yShift # Hide the dotted outline itemOption = QStyleOptionGraphicsItem(option) if itemOption.state & QStyle.State_Selected != 0: itemOption.state = itemOption.state & ~QStyle.State_Selected QGraphicsPathItem.paint(self, painter, itemOption, widget) # Draw the text in the rectangle pen = QPen(settings.commentFGColor) painter.setFont(settings.monoFont) painter.setPen(pen) painter.drawText( self._leftEdge + settings.hCellPadding + settings.hTextPadding, baseY + settings.vCellPadding + settings.vTextPadding, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)
def paint(self, painter, option, widget): """Draws the collapsed group""" del option # unused argument del widget # unused argument settings = self.canvas.settings # Outer rectangle rectWidth = self.minWidth - 2 * settings.hCellPadding rectHeight = self.minHeight - 2 * settings.vCellPadding if self.isSelected(): selectPen = QPen(settings.selectColor) selectPen.setWidth(settings.selectPenWidth) selectPen.setJoinStyle(Qt.RoundJoin) painter.setPen(selectPen) else: pen = QPen(self.__borderColor) painter.setPen(pen) brush = QBrush(self.__bgColor) painter.setBrush(brush) painter.drawRect(self.baseX + settings.hCellPadding, self.baseY + settings.vCellPadding, rectWidth, rectHeight) # Inner rectangle rectWidth -= 2 * settings.collapsedOutlineWidth rectHeight -= 2 * settings.collapsedOutlineWidth pen = QPen(self.__borderColor) painter.setPen(pen) painter.drawRect(self.baseX + settings.hCellPadding + settings.collapsedOutlineWidth, self.baseY + settings.vCellPadding + settings.collapsedOutlineWidth, rectWidth, rectHeight) # Draw the text in the rectangle pen = QPen(self.__fgColor) painter.setFont(settings.monoFont) painter.setPen(pen) textWidth = self.__textRect.width() + 2 * settings.hTextPadding textShift = (rectWidth - textWidth) / 2 painter.drawText( self.baseX + settings.hCellPadding + settings.hTextPadding + settings.collapsedOutlineWidth + textShift, self.baseY + settings.vCellPadding + settings.vTextPadding + settings.collapsedOutlineWidth, self.__textRect.width(), self.__textRect.height(), Qt.AlignLeft, self._getText())
def __init__(self, node, refFile, docstring): QGraphicsRectItem.__init__(self) self.__node = node self.__refFile = refFile self.__docstring = docstring posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) self.setBrush(QColor(220, 255, 220)) # System modules are clickable self.setFlag(QGraphicsItem.ItemIsSelectable, True)
def paint(self, painter, option, widget): """Paints the connector""" color = self.__settings.lineColor if self.penColor: color = self.penColor width = self.__settings.lineWidth if self.penWidth: width = self.penWidth pen = QPen(color) pen.setWidth(width) pen.setCapStyle(Qt.FlatCap) pen.setJoinStyle(Qt.RoundJoin) if self.penStyle: pen.setStyle(self.penStyle) self.setPen(pen) QGraphicsPathItem.paint(self, painter, option, widget)
def __init__(self, node, refFile, srcobj): QGraphicsRectItem.__init__(self) self.__node = node self.__srcobj = srcobj self.__refFile = refFile posX = node.posX - node.width / 2.0 posY = node.posY - node.height / 2.0 QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height) pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) self.setPen(pen) # To make double click delivered self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setBrush(QColor(253, 245, 145))
def paint(self, painter, option, widget): """Paints the line item""" color = self.canvas.settings.cfLineColor if self.penColor: color = self.penColor width = self.canvas.settings.cfLineWidth if self.penWidth: width = self.penWidth pen = QPen(color) pen.setWidth(width) pen.setCapStyle(Qt.FlatCap) pen.setJoinStyle(Qt.RoundJoin) if self.penStyle: pen.setStyle(self.penStyle) self.setPen(pen) QGraphicsLineItem.paint(self, painter, option, widget)
def paint(self, painter, option, widget): """Paints the rubber band""" #s = self.ref.canvas.settings pen = QPen(Qt.black) #pen.setWidth(s.badgeLineWidth) painter.setPen(pen) #brush = QBrush(self.__bgColor) #painter.setBrush(brush) painter.drawRect(self.__x, self.__y, self.__width, self.__height)
def __paintDeclaration(self, painter): """Paints the scope header""" s = self.canvas.settings painter.setBrush(QBrush(self.bgColor)) pen = QPen(self.fgColor) painter.setFont(s.monoFont) painter.setPen(pen) canvasLeft = self.baseX - s.scopeRectRadius canvasTop = self.baseY - s.scopeRectRadius textHeight = self.textRect.height() yShift = 0 if hasattr(self.ref, 'sideComment'): yShift = s.vTextPadding painter.drawText(canvasLeft + s.hHeaderPadding, canvasTop + s.vHeaderPadding + yShift, self.textRect.width(), textHeight, Qt.AlignLeft, self.text) pen = QPen(self.borderColor) pen.setWidth(s.boxLineWidth) painter.setPen(pen) # If the scope is selected then the line may need to be shorter # to avoid covering the outline row = self.addr[1] - 1 column = self.addr[0] - 1 correction = 0.0 if self.canvas.cells[row][column].isSelected(): correction = s.selectPenWidth - 1 painter.drawLine( canvasLeft + correction, self.baseY + self.height, canvasLeft + self.canvas.minWidth - 2 * s.hCellPadding - correction, self.baseY + self.height)
def paint(self, painter, option, widget): """Draws a curve and then adds an arrow""" pen = QPen(QColor(0, 0, 0)) pen.setWidth(2) pen.setStyle(Qt.DotLine) self.setPen(pen) QGraphicsPathItem.paint(self, painter, option, widget)
def paint(self, painter, option, widget): """Draws the code block""" del option # unused argument del widget # unused argument settings = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) takenByBadges = 0 if self.aboveBadges.hasAny(): takenByBadges = self.aboveBadges.height + settings.badgeToScopeVPadding dHalf = int(self.__diamondHeight / 2.0) dx1 = self.baseX + settings.hCellPadding dy1 = self.baseY + takenByBadges + int((self.minHeight - takenByBadges)/2) dx2 = dx1 + settings.ifWidth dy2 = dy1 - dHalf dx3 = dx1 + self.__diamondWidth - settings.ifWidth dy3 = dy2 dx4 = dx3 + settings.ifWidth dy4 = dy1 dx5 = dx3 dy5 = dy2 + 2 * dHalf dx6 = dx2 dy6 = dy5 painter.drawPolygon(QPointF(dx1, dy1), QPointF(dx2, dy2), QPointF(dx3, dy3), QPointF(dx4, dy4), QPointF(dx5, dy5), QPointF(dx6, dy6)) painter.drawRect(dx4 + 1, self.baseY + settings.vCellPadding + takenByBadges, self.minWidth - 2 * settings.hCellPadding - self.__diamondWidth, self.minHeight - 2 * settings.vCellPadding - takenByBadges) # Draw the text in the rectangle pen = QPen(self.fgColor) painter.setFont(settings.monoFont) painter.setPen(pen) availWidth = \ self.minWidth - 2 * settings.hCellPadding - self.__diamondWidth textWidth = self.textRect.width() + 2 * settings.hTextPadding textShift = (availWidth - textWidth) / 2 painter.drawText( dx4 + settings.hTextPadding + textShift, self.baseY + settings.vCellPadding + settings.vTextPadding + takenByBadges, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)
def paint(self, painter, option, widget): """Draws a filled rectangle and then adds a title""" # Draw the rectangle QGraphicsRectItem.paint(self, painter, option, widget) # Draw text over the rectangle font = QFont("Arial", 10) font.setBold(True) painter.setFont(font) painter.setPen(QPen(QColor(90, 90, 88))) painter.drawText(self.__node.posX - self.__node.width / 2.0, self.__node.posY - self.__node.height / 2.0, self.__node.width, self.__node.height, Qt.AlignCenter, self.__node.label)
def __paintTopLeft(self, painter): """Paints the scope rectangle""" s = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) yPos = self.baseY + s.vCellPadding height = self.canvas.minHeight - 2 * s.vCellPadding if self.aboveBadges.hasAny(): badgeShift = self.aboveBadges.height + s.badgeToScopeVPadding yPos += badgeShift height -= badgeShift if self.kind in [CellElement.FOR_SCOPE, CellElement.WHILE_SCOPE]: cellBelow = self.canvas.cells[self.addr[1] + 1][self.addr[0]] halfDeclHeight = (cellBelow.height + s.scopeRectRadius) / 2 yPos += halfDeclHeight height -= halfDeclHeight painter.drawRoundedRect(self.baseX + s.hCellPadding, yPos, self.canvas.minWidth - 2 * s.hCellPadding, height, s.scopeRectRadius, s.scopeRectRadius) if self.kind in [CellElement.FOR_SCOPE, CellElement.WHILE_SCOPE]: # Brush if self.kind == CellElement.FOR_SCOPE: painter.setBrush(QBrush(s.forScopeHeaderBGColor)) else: painter.setBrush(QBrush(s.whileScopeHeaderBGColor)) # Pen, if not selected if not self.isSelected(): if self.kind == CellElement.FOR_SCOPE: pen = QPen(QColor(s.forScopeHeaderBorderColor)) pen.setWidth(s.forScopeHeaderPenWidth) else: pen = QPen(QColor(s.whileScopeHeaderBorderColor)) pen.setWidth(s.whileScopeHeaderPenWidth) painter.setPen(pen) painter.drawPolygon(QPointF(self.x1, self.y1), QPointF(self.x2, self.y2), QPointF(self.x3, self.y3), QPointF(self.x4, self.y4), QPointF(self.x5, self.y5), QPointF(self.x6, self.y6))
def paint(self, painter, option, widget): """Draws the code block""" settings = self.canvas.settings pen = QPen(settings.cfLineColor) pen.setWidth(settings.cfLineWidth) pen.setJoinStyle(Qt.RoundJoin) self.setPen(pen) painter.setPen(pen) QGraphicsPathItem.paint(self, painter, option, widget)
def paint(self, painter, option, widget): """Paints the badge item""" del option del widget self.paintBadgeRectangle(painter, self.isSelected(), self.borderColor, self.bgColor) s = self.ref.canvas.settings pen = QPen(self.fgColor) painter.setPen(pen) painter.setFont(s.badgeFont) painter.drawText( self.x() + s.badgeHSpacing + (self.width - self.minWidth) / 2, self.y() + s.badgeVSpacing, self.textRect.width(), self.textRect.height(), Qt.AlignCenter, self.text)
def draw(self, scene, baseX, baseY): """Draws the diagram on the real canvas""" self.baseX = baseX self.baseY = baseY currentY = baseY for row in self.cells: if not row: continue height = row[0].height currentX = baseX for cell in row: if self.settings.debug: pen = QPen(Qt.DotLine) pen.setWidth(1) if cell.kind == CellElement.VCANVAS: pen.setColor(QColor(255, 0, 0, 255)) scene.addLine(currentX + 1, currentY + 1, currentX + cell.width - 2, currentY + 1, pen) scene.addLine(currentX + 1, currentY + 1, currentX + 1, currentY + cell.height - 2, pen) scene.addLine(currentX + 1, currentY + cell.height - 2, currentX + cell.width - 2, currentY + cell.height - 2, pen) scene.addLine(currentX + cell.width - 2, currentY + 1, currentX + cell.width - 2, currentY + cell.height - 2, pen) else: pen.setColor(QColor(0, 255, 0, 255)) scene.addLine(currentX, currentY, currentX + cell.width, currentY, pen) scene.addLine(currentX, currentY, currentX, currentY + cell.height, pen) scene.addLine(currentX, currentY + cell.height, currentX + cell.width, currentY + cell.height, pen) scene.addLine(currentX + cell.width, currentY, currentX + cell.width, currentY + cell.height, pen) cell.draw(scene, currentX, currentY) currentX += cell.width currentY += height
def paintCell(self, painter, rectRadius): """Draws the cell""" settings = self.canvas.settings painter.setPen(self.getPainterPen(self.isSelected(), self.borderColor)) painter.setBrush(QBrush(self.bgColor)) painter.drawRoundedRect(self.xPos, self.yPos, self.rectWidth, self.rectHeight, rectRadius, rectRadius) # Draw the text in the rectangle pen = QPen(self.fgColor) painter.setFont(settings.monoFont) painter.setPen(pen) hShift = (self.rectWidth - self.textRect.width()) / 2 vShift = (self.rectHeight - self.textRect.height()) / 2 painter.drawText(self.xPos + hShift, self.yPos + vShift, self.textRect.width(), self.textRect.height(), Qt.AlignLeft, self.text)