def paintEvent(self, event): p = QtGui.QPainter(self) r = self.rect() opt = QtGui.QStyleOptionToolButton() opt.init(self) opt.state |= QtGui.QStyle.State_AutoRaise if self.isEnabled() and self.underMouse() and \ not self.isChecked() and not self.isDown(): opt.state |= QtGui.QStyle.State_Raised if self.isChecked(): opt.state |= QtGui.QStyle.State_On if self.isDown(): opt.state |= QtGui.QStyle.State_Sunken self.style().drawPrimitive(QtGui.QStyle.PE_PanelButtonTool, opt, p, self) opt.icon = self.icon() opt.subControls = QtGui.QStyle.SubControls() opt.activeSubControls = QtGui.QStyle.SubControls() opt.features = QtGui.QStyleOptionToolButton.None opt.arrowType = QtCore.Qt.NoArrow size = self.style().pixelMetric(QtGui.QStyle.PM_SmallIconSize, None, self) opt.iconSize = QtCore.QSize(size, size) self.style().drawComplexControl(QtGui.QStyle.CC_ToolButton, opt, p, self)
def paintEvent(self, event): font_metrics = QtGui.QFontMetrics(self.editor.font) page_bottom = self.editor.viewport().height() lineHeight = font_metrics.height() scrollBar = self.editor.verticalScrollBar() if scrollBar.isVisible(): rectRelation = float(scrollBar.height()) / float(self.editor.document().blockCount()) else: rectRelation = lineHeight rectHeight = round(rectRelation) if rectRelation >= 1 else 1 painter = QtGui.QPainter(self) painter.fillRect(self.rect(), self.background) viewport_offset = self.editor.contentOffset() for extra in self.editor.searchExtraSelections("selection"): y = round(extra.cursor.block().blockNumber() * rectRelation) if rectRelation == lineHeight: y += viewport_offset.y() painter.fillRect(0, y, 10, rectHeight, self.editor.colours['selection']) painter.end() QtGui.QWidget.paintEvent(self, event)
def paintEvent(self, event): font_metrics = QtGui.QFontMetrics(self.editor.font) page_bottom = self.editor.viewport().height() painter = QtGui.QPainter(self) painter.fillRect(self.rect(), self.background) block = self.editor.firstVisibleBlock() viewport_offset = self.editor.contentOffset() while block.isValid(): # The top left position of the block in the document position = self.editor.blockBoundingGeometry(block).topLeft() + viewport_offset # Check if the position of the block is out side of the visible area if position.y() > page_bottom: break # Draw the line number right justified at the y position of the line. if block.isVisible() and block in self.editor.bookmarkListModel: painter.drawPixmap(0, round(position.y()) + font_metrics.ascent() + font_metrics.descent() - self.bookmarkflagImage.height(), self.bookmarkflagImage) block = block.next() painter.end() QtGui.QWidget.paintEvent(self, event)
def paintEvent(self, event): font_metrics = QtGui.QFontMetrics(self.editor.font) page_bottom = self.editor.viewport().height() painter = QtGui.QPainter(self) painter.fillRect(self.rect(), self.background) block = self.editor.firstVisibleBlock() viewport_offset = self.editor.contentOffset() while block.isValid(): # The top left position of the block in the document position = self.editor.blockBoundingGeometry(block).topLeft() + viewport_offset # Check if the position of the block is out side of the visible area if position.y() > page_bottom: break # Draw the line number right justified at the y position of the line. if block.isVisible(): userData = block.userData() mark = self.editor.folding.getFoldingMark(block) if self.editor.folding.isStart(mark): if userData.folded: painter.drawPixmap(0, round(position.y()) + font_metrics.ascent() + font_metrics.descent() - self.foldingcollapsedImage.height(), self.foldingcollapsedImage) else: painter.drawPixmap(0, round(position.y()) + font_metrics.ascent() + font_metrics.descent() - self.foldingtopImage.height(), self.foldingtopImage) elif self.editor.folding.isStop(mark): painter.drawPixmap(0, round(position.y()) + font_metrics.ascent() + font_metrics.descent() - self.foldingbottomImage.height(), self.foldingbottomImage) block = block.next() painter.end() QtGui.QWidget.paintEvent(self, event)
def paintEvent(self, event): page_bottom = self.editor.viewport().height() current_block = self.editor.document().findBlock(self.editor.textCursor().position()) painter = QtGui.QPainter(self) painter.setPen(self.foreground) painter.fillRect(self.rect(), self.background) block = self.editor.firstVisibleBlock() viewport_offset = self.editor.contentOffset() line_count = block.blockNumber() while block.isValid(): line_count += 1 # The top left position of the block in the document position = self.editor.blockBoundingGeometry(block).topLeft() + viewport_offset # Check if the position of the block is out side of the visible area if position.y() > page_bottom: break # Draw the line number right justified at the y position of the line. if block.isVisible(): numberText = str(line_count) if block == current_block: painter.setFont(self.boldFont) leftPosition = self.width() - (self.boldMetrics.width(numberText) + self.MARGIN) topPosition = position.y() + self.boldMetrics.ascent() + self.boldMetrics.descent() - 2 painter.drawText(leftPosition, topPosition, numberText) else: painter.setFont(self.normalFont) leftPosition = self.width() - (self.normalMetrics.width(numberText) + self.MARGIN) topPosition = position.y() + self.normalMetrics.ascent() + self.normalMetrics.descent() - 2 painter.drawText(leftPosition, topPosition, numberText) block = block.next() painter.end() QtGui.QWidget.paintEvent(self, event)
def combine_icons(icon1, icon2, scale=1): newIcon = QtGui.QIcon() sizes = icon1.availableSizes() if not sizes: sizes = [ QtCore.QSize(16, 16), QtCore.QSize(22, 22), QtCore.QSize(32, 32), QtCore.QSize(48, 48) ] for size in sizes: pixmap1 = icon1.pixmap(size) pixmap2 = icon2.pixmap(size) pixmap2 = pixmap2.scaled(pixmap1.width() * scale, pixmap1.height() * scale) result = QtGui.QPixmap(size) result.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(result) painter.drawPixmap(0, 0, pixmap1) painter.drawPixmap(pixmap1.width() - pixmap2.width(), pixmap1.height() - pixmap2.height(), pixmap2) painter.end() newIcon.addPixmap(result) return newIcon