def _drawMonthFrame(self): self.initMonthInfo() wi = self.month_info painter = QPainter(self) pen = painter.pen() pen.setWidth(Var.line_width) painter.setPen(pen) for coord in wi.paint_base_lines: painter.drawLine(*coord) # Draw selections for selection in wi.selections(): painter.fillRect(*selection) # Draw dates font = painter.font() font.setPointSize(wi.cell_height/8) painter.setFont(font) for cell_id in range(42): x, y = wi.getCoordinate(cell_id) x += wi.cell_width * 74/100 y += wi.cell_height/7 day = wi.getDay(cell_id) painter.drawText(QPointF(x, y), QString(str(day)))
def paintEvent(self, event): super(DetailedProgress, self).paintEvent(event) if not self._current_progress: return painter = QPainter(self) width = self.width() height = self.height() aspect_ratio = float(width)/height nr_realizations = len(self._current_progress) fm_size = len(self._current_progress[0][1]) self.grid_height = math.ceil(math.sqrt(nr_realizations / aspect_ratio)) self.grid_width = math.ceil(self.grid_height * aspect_ratio) sub_grid_size = math.ceil(math.sqrt(fm_size)) cell_height = height / self.grid_height cell_width = width / self.grid_width foreground_image = QImage(self.grid_width*sub_grid_size, self.grid_height*sub_grid_size, QImage.Format_ARGB32) foreground_image.fill(QColor(0, 0, 0, 0)) for index, (iens, progress) in enumerate(self._current_progress): y = int(iens / self.grid_width) x = int(iens - (y * self.grid_width)) self.draw_window(x * sub_grid_size, y * sub_grid_size, progress, foreground_image) painter.drawImage(self.contentsRect(), foreground_image) for index, (iens, progress) in enumerate(self._current_progress): y = int(iens / self.grid_width) x = int(iens - (y * self.grid_width)) if iens == self.selected_realization: painter.setPen(QColor(240, 240, 240)) else: painter.setPen(QColor(80, 80, 80)) painter.drawRect(x * cell_width, y * cell_height, cell_width-1, cell_height-1) painter.drawText(x * cell_width + cell_width / 2, y * cell_height + cell_height / 2, str(iens))
def __write(self, text, font, pen): width = QFontMetrics(font).width(text+' ') painter = QPainter(self) painter.setFont(font) painter.setPen(pen) painter.drawText(self.spaceLeft, Qt.AlignBottom, text) self.spaceLeft.setLeft(self.spaceLeft.left() + width ) # move the left edge to the end of what we just painted.
def draw_image(name, q): image = QSvgGenerator() image.setSize(QSize(IMAGE_SIZE, IMAGE_SIZE)) image.setFileName(name + ".svg") painter = QPainter() painter.begin(image) painter.setBrush(Qt.white) painter.setPen(Qt.NoPen) painter.drawEllipse(QPointF(IMAGE_SIZE/2, IMAGE_SIZE/2), IMAGE_SIZE/2, IMAGE_SIZE/2) painter.setBrush(QBrush()) painter.setPen(QPen()) draw_defect(painter, q) draw_circle(painter, q) pen = QPen() pen.setWidth(7) pen.setColor(Qt.red) painter.setPen(pen) painter.drawLine(IMAGE_SIZE/2 - ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2) painter.drawLine(IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 + 20) painter.drawLine(IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 - 20) font = painter.font() font.setPixelSize(40) font.setBold(True) painter.setFont(font) painter.drawText(QPointF(IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 - 30), "E") painter.end()
def paintEvent(self, event): p = QPainter(self) p.fillRect(event.rect(), Qt.white) start = self.m_offset / self.m_height y = start * self.m_height - self.m_offset if self.m_offset <= 0: start = 0 y = -self.m_offset end = start + self.height() / self.m_height + 1 if end > len(self.m_colorNames) - 1: end = len(self.m_colorNames) - 1 for i in range(start, end): p.setBrush(Qt.NoBrush) p.setPen(Qt.black) if i == self.m_highlight: p.fillRect(0, y, self.width(), self.m_height, QColor(0, 64, 128)) p.setPen(Qt.white) if i == self.m_selected: p.fillRect(0, y, self.width(), self.m_height, QColor(0, 128, 240)) p.setPen(Qt.white) p.drawText(self.m_height + 2, y, self.width(), self.m_height, Qt.AlignVCenter, self.m_colorNames[i]) p.setPen(Qt.NoPen) p.setBrush(QBrush(self.m_firstColor[i])) p.drawRect(1, y + 1, self.m_height - 2, self.m_height - 2) p.setBrush(QBrush(self.m_secondColor[i])) p.drawRect(5, y + 5, self.m_height - 11, self.m_height - 11) y += self.m_height p.end()
def paintEvent(self, event): """ paint a circle for each bp """ painter = QPainter(self) painter.fillRect(event.rect(), self.palette().color(QPalette.Window)) painter.setPen(Qt.black) block = self.main_editor.firstVisibleBlock() block_num = block.blockNumber() top = int(self.main_editor.blockBoundingGeometry(block).translated( self.main_editor.contentOffset()).top()) bottom = top + int(self.main_editor.blockBoundingRect(block).height()) bounding_rect = self.main_editor.blockBoundingRect(block) bp_brush = QBrush(QColor(250, 0, 0, 128)) while block.isValid() and top <= event.rect().bottom(): if block.isVisible() and bottom >= event.rect().top(): line = block_num + 1 width = self.width() - self.MARGIN height = self.main_editor.fontMetrics().height() painter.setPen(Qt.black) painter.drawText(0, top, width, height, Qt.AlignRight, str(line)) if line in self.breakpoints: # paint break point diameter = min(width, height) - 3 painter.setPen(Qt.NoPen) painter.setBrush(bp_brush) painter.drawEllipse((width - diameter) / 2, top + 1.5, diameter, diameter) block = block.next() bounding_rect = self.main_editor.blockBoundingRect(block) top = bottom bottom = top + int(bounding_rect.height()) block_num += 1
def paintEvent(self, event): """QWidget.paintEvent() implementation """ painter = QPainter(self) painter.fillRect(event.rect(), self.palette().color(QPalette.Window)) painter.setPen(Qt.black) block = self._qpart.firstVisibleBlock() blockNumber = block.blockNumber() top = int(self._qpart.blockBoundingGeometry(block).translated(self._qpart.contentOffset()).top()) bottom = top + int(self._qpart.blockBoundingRect(block).height()) singleBlockHeight = self._qpart.cursorRect().height() width = None boundingRect = self._qpart.blockBoundingRect(block) while block.isValid() and top <= event.rect().bottom(): if block.isVisible() and bottom >= event.rect().top(): number = str(blockNumber + 1) painter.drawText(0, top, self.width() - self._RIGHT_MARGIN, self._qpart.fontMetrics().height(), Qt.AlignRight, number) if boundingRect.height() >= singleBlockHeight * 2: # wrapped block if width is None: width = self.width() # laizy calculation painter.fillRect(1, top + singleBlockHeight, width - 2, boundingRect.height() - singleBlockHeight - 2, Qt.darkGreen) block = block.next() boundingRect = self._qpart.blockBoundingRect(block) top = bottom bottom = top + int(boundingRect.height()) blockNumber += 1
def paintEvent(self, event): """ Overloads the paint event to support rendering of hints if there are no items in the tree. :param event | <QPaintEvent> """ super(XTextEdit, self).paintEvent(event) if self.document().isEmpty() and self.hint(): text = self.hint() rect = self.rect() # modify the padding on the rect rect.setX(4) rect.setY(4) align = int(Qt.AlignLeft | Qt.AlignTop) # setup the coloring options clr = self.hintColor() # paint the hint painter = QPainter(self.viewport()) painter.setPen(clr) painter.drawText(rect, align | Qt.TextWordWrap, text)
def paintEvent(self, paintEvent): painter = QPainter(self) painter.setPen(QPen(Qt.white)) painter.drawText(QPointF(14, self.height()-16), str(self.message)) painter.setPen(QPen(QBrush(QColor(58, 93, 208)), 8)) if self.progress > 0.0: painter.drawLine(0, self.height()-4, self.progress * self.width(), self.height()-4)
def paintEvent(self, event): painter = QPainter() painter.begin(self) if not self.showRegionMap: painter.drawPixmap(0, 0, self.scaledOwnershipMap) rect = self.imageRect() if self.isEnabled(): if self.showRegionMap: painter.drawPixmap(0, 0, self.scaledRegionMap) else: if self.currentTerritory: painter.drawPixmap(0, 0, self.coloredMask(self.currentTerritory, QColor(*self.game.clientPlayer.color))) #draw active animations for a in self.animations: painter.save() a.paint(painter) painter.restore() painter.drawPixmap(0, 0, self.scaledTroopCountMap) else: painter.fillRect(rect, QColor(0, 0, 0, 200)) painter.drawText(rect, Qt.AlignCenter, "Waiting for the game to start.") #remaining troops if self.game.yourTurn() and self.game.remainingTroops: troopText = "Remaining troops: %d" % self.game.remainingTroops troopRect = QRect(0, 0, painter.fontMetrics().width(troopText) + 8, painter.fontMetrics().height() + 8) troopRect.moveBottomLeft(rect.bottomLeft()) painter.setPen(Qt.white) painter.setBrush(QColor(0, 0, 0, 200)) painter.drawRect(troopRect) painter.drawText(troopRect, Qt.AlignCenter, troopText) painter.end()
def printFile(self): # Needs some work... printDialog = QPrintDialog(self.printer, py_de) if printDialog.exec_() == QDialog.Accepted: margin = 10 pageNum = 1 yPos = 0 printJob = QPainter() printJob.begin(self.printer) printJob.setFont(self.font) fm = printJob.fontMetrics() for i in range(self.textEdit.lines()): if margin + yPos > self.printer.height() - margin: pageNum += 1 self.printer.newPage() yPos = 0 printJob.drawText(margin, # X margin + yPos, # Y self.printer.width(), # Width self.printer.height(),# Height QtCore.Qt.AlignTop, # Alignment self.textEdit.text(i - 1)# The text to print ) yPos += fm.lineSpacing() printJob.end
def drawROIBoxes(self, image): #print(self.frame_data) if not isinstance(self.frame_data, pd.DataFrame) or len(self.frame_data) == 0 \ or not self.label_type in self.frame_data: return self.img_h_ratio = image.height()/self.image_height; self.img_w_ratio = image.width()/self.image_width; painter = QPainter() painter.begin(image) for row_id, row_data in self.frame_data.iterrows(): x = row_data['coord_x']*self.img_h_ratio y = row_data['coord_y']*self.img_w_ratio #check if the coordinates are nan if not (x == x) or not (y == y): continue x = int(x) y = int(y) c = self.wlabC[int(row_data[self.label_type])] painter.setPen(c) painter.setFont(QFont('Decorative', 10)) painter.drawText(x, y, str(int(row_data[self.worm_index_type]))) bb = row_data['roi_size']*self.img_w_ratio painter.drawRect(x-bb/2, y-bb/2, bb, bb); painter.end()
def paintEvent( self, event ): """ Overloads the paint event to support rendering of hints if there are no items in the tree. :param event | <QPaintEvent> """ super(XListWidget, self).paintEvent(event) if not self.count() and self.hint(): text = self.hint() rect = self.rect() # modify the padding on the rect rect.setX(rect.x() + 2) rect.setY(rect.y() + 2) rect.setWidth(rect.width() - 4) rect.setHeight(rect.height() - 4) align = int(self.hintAlignment()) # setup the coloring options clr = self.hintColor() # paint the hint painter = QPainter(self.viewport()) painter.setPen(clr) painter.drawText(rect, align | Qt.TextWordWrap, text)
def paintEvent(self, e): Part.paintEvent(self, e) painter = QPainter(self) color = QColor(self._base.dark(150)) color.setAlpha(150) painter.setPen(color) painter.pen().setWidth(2) painter.drawPolyline(*tuple(self._SYNTH_POINTS)) if not self.songpart is None and self.activeLED.isHidden(): color = QColor('black') color.setAlpha(200) painter.setPen(color) rect = QRect(0, 5, self.width() - 5, self.height() - 5) painter.drawText(rect, Qt.AlignRight | Qt.AlignTop, '[%s]' % self.songpart) painter.setPen(self._base.light(150)) painter.pen().setWidth(self.margin) y = self.height() - self.margin synth = self.data for start, stop in self.paintNotes: ratio = 1 - ((stop - synth.localclock.time()) / (stop - start)) if ratio > 0 and ratio <= 1: width = (self.width() - self.margin * 2) * ratio painter.drawLine(self.margin, y, width, y) y -= (self.margin + 3) painter = None self.drawText()
def paintEvent(self, e): painter = QPainter() reactantside = "" productside = "" reactantside += self._CurrentReaction.GetReactants()[0].GetFormula() for x in range(1, len(self._CurrentReaction.GetReactants())): reactant = self._CurrentReaction.GetReactants()[x] formula = reactant.GetFormula() moles = reactant.GetInitialMoles() if moles > 0: reactantside += " + "+formula productside += self._CurrentReaction.GetProducts()[0].GetFormula() for x in range(1, len(self._CurrentReaction.GetProducts())): product = self._CurrentReaction.GetProducts()[x] formula = product.GetFormula() moles = product.GetInitialMoles() if moles > 0: productside += " + "+formula painter.begin(self) painter.setFont(QFont("Arial", 20, 50, False)) painter.setPen(QPen(Qt.red, 2, Qt.SolidLine)) painter.drawText(376 - (len(reactantside) * 15), 40, reactantside) target = QRectF(378, 20, 44, 32) arrows = QPixmap("assets/double arrow.png") portion = QRectF(10, 0, 44, 32) painter.drawPixmap(target, arrows, portion) painter.setPen(QPen(Qt.blue, 2, Qt.SolidLine)) painter.drawText(425, 40, productside) painter.end()
def splash_screen(): """ """ pm = QPixmap( pkg_resources.resource_filename( __name__, "icons/orange-splash-screen.png") ) version = QCoreApplication.applicationVersion() size = 21 if len(version) < 5 else 16 font = QFont("Helvetica") font.setPixelSize(size) font.setBold(True) font.setItalic(True) font.setLetterSpacing(QFont.AbsoluteSpacing, 2) metrics = QFontMetrics(font) br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0) br.moveCenter(QPoint(436, 224)) p = QPainter(pm) p.setRenderHint(QPainter.Antialiasing) p.setRenderHint(QPainter.TextAntialiasing) p.setFont(font) p.setPen(QColor("#231F20")) p.drawText(br, Qt.AlignCenter, version) p.end() return pm, QRect(88, 193, 200, 20)
def paintEvent( self, event ): """ Overloads the paint event for this menu to draw its title based on its \ show title property. :param event | <QPaintEvent> """ super(XMenu, self).paintEvent(event) if ( self.showTitle() ): painter = QPainter() painter.begin(self) palette = self.palette() painter.setBrush(palette.color(palette.Button)) painter.setPen(Qt.NoPen) painter.drawRect(1, 1, self.width() - 2, 22) painter.setBrush(Qt.NoBrush) painter.setPen(palette.color(palette.ButtonText)) painter.drawText(1, 1, self.width() - 2, 22, Qt.AlignCenter, self.title()) painter.end()
def paintEvent(self, event): 'Paint semi-transparent background, animated pattern, background text' QWidget.paintEvent(self, event) # make a painter p = QPainter(self) p.setRenderHint(QPainter.TextAntialiasing) p.setRenderHint(QPainter.HighQualityAntialiasing) # fill a rectangle with transparent painting p.fillRect(event.rect(), Qt.transparent) # animated random dots background pattern for i in range(4096): x = randint(9, self.size().width() - 9) y = randint(9, self.size().height() - 9) p.setPen(QPen(QColor(randint(200, 255), randint(200, 255), 255), 1)) p.drawPoint(x, y) # set pen to use white color p.setPen(QPen(QColor(randint(9, 255), randint(9, 255), 255), 1)) # Rotate painter 45 Degree p.rotate(35) # Set painter Font for text p.setFont(QFont('Ubuntu', 300)) # draw the background text, with antialiasing p.drawText(99, 199, "Radio") # Rotate -45 the QPen back ! p.rotate(-35) # set the pen to no pen p.setPen(Qt.NoPen) # Background Color p.setBrush(QColor(0, 0, 0)) # Background Opacity p.setOpacity(0.75) # Background Rounded Borders p.drawRoundedRect(self.rect(), 50, 50) # finalize the painter p.end()
def paintEvent(self, event): """ custom paint event to draw vertical text """ painter = QPainter(self) # draw box around arc_size, line_width=10, 1 pen = QPen(QtCore.Qt.gray) pen.setWidth(line_width) painter.setPen(pen) painter.drawLine(arc_size,0, self.width(), 0) painter.drawLine(0, arc_size,0, self.height()-arc_size) painter.drawLine(arc_size-5,self.height()-1,self.width(), self.height()-1) painter.drawArc(0,0, arc_size*2, arc_size*2, 180*16, -90*16) painter.drawArc(0,self.height()-arc_size*2, arc_size*2, arc_size*2, 180*16, 90*16) # draw box around #if (self.isEnabled()): if self.selected: painter.setPen(QtCore.Qt.black) else: painter.setPen(QtCore.Qt.gray) painter.translate(self.width(), self.height()) painter.rotate(270) painter.drawText(QtCore.QPointF(10,- self.width()/3), self.text()) # destroy del painter
def paintEvent(self, event=None): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, True) xOffset = self.width() / SIZE yOffset = self.height() / SIZE for x in range(SIZE): for y in range(SIZE): cell = self.grid[x][y] rect = (QRectF(x * xOffset, y * yOffset, xOffset, yOffset).adjusted(0.5, 0.5, -0.5, -0.5)) great_rect = QRectF(x * xOffset, y * yOffset, xOffset, yOffset) if cell != BLANK: painter.save() painter.setPen(Qt.black) font = QFont() font.setPointSize(20) painter.setFont(font) painter.drawText(rect, Qt.AlignCenter, cell) painter.restore() if [x, y] == self.selected: painter.setPen(QPen(Qt.blue, SIZE)) else: painter.setPen(Qt.black) painter.drawRect(rect)
def paintEvent( self, event ): painter = QPainter(self) metrics = QFontMetrics(self.font()) elided = metrics.elidedText(self.text(), QtCore.Qt.ElideLeft, self.width()) painter.drawText(self.rect(), self.alignment(), elided)
def paintEvent(self, event): """ Reimplements the :meth:`QWidget.paintEvent` method. :param event: Event. :type event: QEvent """ def __setBold(state): """ Sets the current painter font bold state. :return: Definiton success. :rtype: bool """ font = painter.font() font.setBold(state) painter.setFont(font) return True painter = QPainter(self) painter.fillRect(event.rect(), self.__backgroundColor) pen = QPen(QBrush(), self.__separatorWidth) pen.setColor(self.__separatorColor) painter.setPen(pen) topRightCorner = event.rect().topRight() bottomRightCorner = event.rect().bottomRight() painter.drawLine(topRightCorner.x(), topRightCorner.y(), bottomRightCorner.x(), bottomRightCorner.y()) painter.setPen(self.__color) viewportHeight = self.__editor.viewport().height() metrics = QFontMetrics(self.__editor.document().defaultFont()) currentBlock = self.__editor.document().findBlock( self.__editor.textCursor().position()) block = self.__editor.firstVisibleBlock() blockNumber = block.blockNumber() painter.setFont(self.__editor.document().defaultFont()) while block.isValid(): blockNumber += 1 position = self.__editor.blockBoundingGeometry(block).topLeft() + self.__editor.contentOffset() if position.y() > viewportHeight: break if not block.isVisible(): continue block == currentBlock and __setBold(True) or __setBold(False) painter.drawText(self.width() - metrics.width(foundations.strings.toString(blockNumber)) - self.__margin / 3, round(position.y() + metrics.ascent() + metrics.descent() - \ (self.__editor.blockBoundingRect(block).height() * 8.0 / 100)), foundations.strings.toString(blockNumber)) block = block.next() painter.end() QWidget.paintEvent(self, event)
def paintEvent(self, e: QPaintEvent): if e.isAccepted(): p = QPainter(self) p.setPen(QColor(255, 255, 255)) c = self.__node.type().color().darker() p.setBrush(QColor(c.red(), c.green(), c.blue(), 180)) p.drawRoundedRect(1, 1, self.width() - 2, self.height() - 2, 5, 5) p.drawText(QRect(5, 5, self.width() - 10, self.height() - 10), Qt.AlignCenter, self.__name)
def _paint_title(self, p: QPainter): f = p.font() f.setBold(True) f.setPointSize(8) p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 180)) p.setFont(f) title = str(self.name()) + ' : ' + self.type_name() p.drawText(QRectF(6 + Block.padding, 25 + Block.padding, self.width() - 12, 15), title)
def paintEvent(self, e): p = QPainter(self) p.setPen(self.palette().color(QPalette.Text)) m = QMatrix() m.rotate(-90) m.translate(-94, 2) p.setMatrix(m) p.drawText(3, 10, self.text())
def display_cursor(self): painter = QPainter(self) col = self.cur_pos y = self.fixed_font_metrics.ascent() + ((self.height - 1) * self.fixed_font_height) x = 1 + ((col - 1) * self.fixed_font_width) painter.setPen(self.ztoq_color(self.cur_fg)) painter.setBackground(QBrush(self.ztoq_color(self.cur_bg))) painter.drawText(x,y,unichr(0x2581))
def paintEvent(self,event): titleHeight = 40 bottomHeight = 50 #画标题背景 painter = QPainter(self) painter.save() linearGradient = QLinearGradient(0, 0,0,titleHeight) linearGradient.setColorAt(0, QColor(60,150,255)) linearGradient.setColorAt(0.1, QColor(6,88,200)) linearGradient.setColorAt(1, QColor(80,150,255)) painter.setBrush(QBrush(linearGradient)) contenRect = QRect(0, 0, self.width(), titleHeight) painter.fillRect(contenRect, QBrush(linearGradient)) painter.restore() #画标题内容 painter.save() painter.setPen(QPen(QColor(255, 255, 255),1)) font = painter.font() font.setPointSize(12) painter.setFont(font) painter.drawText(QPoint(10,25), self.title) painter.restore() #画中间白色背景 painter.save() painter.setPen(QPen(QColor(255, 255, 255),1)) brush = QBrush(QColor(242,242,242)) painter.setBrush(brush) contenRect = QRect(0, titleHeight, self.width()-1, self.height() - titleHeight - bottomHeight) # painter.fillRect(contenRect, brush) painter.drawRect(contenRect) painter.restore() #画提示信息内容 painter.save() painter.setPen(QPen(QColor(1, 1, 1),1)) font = painter.font() font.setPointSize(15) painter.setFont(font) fm = QFontMetrics(font) infoWidth = fm.width(self.hintInfo) painter.drawText(QPoint((self.width() - infoWidth - 10)/2, 150), self.hintInfo) painter.restore() #画底层背景 painter.save() brush = QBrush(QColor(219,234,255)) painter.setBrush(brush) contenRect = QRect(0, self.height() - bottomHeight, self.width(), bottomHeight) painter.fillRect(contenRect, brush) painter.restore()
def paintEvent(self, event): painter = QPainter(self) rect = self.geometry() text_rect = QRect(0, 0, rect.width(), rect.height()) painter.translate(text_rect.bottomLeft()) painter.rotate(-90) painter.drawText(QRect(QPoint(0, 0), QSize(rect.height(), rect.width())), Qt.AlignCenter, self.text()) painter.end()
def paintEvent(self, event) : painter = QPainter(self.viewport()) painter.translate(-self.horizontalScrollBar().value() * self.font_width, 0) word_count = 0 #// pixel offset of self row row = 0 chars_per_row = self.bytesPerRow() #// current actual offset (in bytes) offset = self.verticalScrollBar().value() * chars_per_row if(self.origin != 0) : if(offset > 0) : offset += self.origin offset -= chars_per_row else : self.origin = 0 self.updateScrollbars() data_size = self.dataSize() widget_height = self.height() while(row + self.font_height < widget_height ) and (offset < data_size) : row_data = self.data[offset:chars_per_row+offset] if( row_data is not None ) : # != '' ? if(self.show_address) : address_rva = self.address_offset + offset addressBuffer = self.formatAddress(address_rva) painter.setPen(QPen(self.address_color)) painter.drawText(0, row, len(addressBuffer) * (self.font_width+1), self.font_height, Qt.AlignTop, addressBuffer) painter.setPen(QPen(Qt.black)) if(self.show_hex) : self.drawHexDump(painter, offset, row, data_size, word_count, row_data) if(self.show_ascii) : self.drawAsciiDump(painter, offset, row, data_size, row_data) #if(self.show_comments and self.comment_server) : # self.drawComments(painter, offset, row, data_size) offset += chars_per_row row += self.font_height painter.setPen(QPen(self.palette().shadow().color())) if(self.show_address and self.show_line1) : line1_x = self.line1() painter.drawLine(line1_x, 0, line1_x, widget_height) if(self.show_hex and self.show_line2) : line2_x = self.line2() painter.drawLine(line2_x, 0, line2_x, widget_height) if(self.show_ascii and self.show_line3) : line3_x = self.line3() painter.drawLine(line3_x, 0, line3_x, widget_height) return
def __init__(self, num, parent=None): super(ViewedNoteIcon, self).__init__(parent) pixmap = QPixmap(16, 16) pixmap.fill(Qt.cyan) rect = QRect(0, 0, 16, 16) painter = QPainter(pixmap) painter.drawText(rect, Qt.AlignHCenter | Qt.AlignVCenter, str(num)) self.addPixmap(pixmap) del painter
def paintEvent(self, event): """ Paint the widget event """ contents_y = self.edit.verticalScrollBar().value() page_bottom = contents_y + self.edit.viewport().height() font_metrics = self.fontMetrics() current_block = self.edit.document().findBlock( self.edit.textCursor().position()) painter = QPainter(self) line_count = 0 # Iterate over all text blocks in the document. block = self.edit.document().begin() while block.isValid(): line_count += 1 # The top left position of the block in the document position = self.edit.document().documentLayout( ).blockBoundingRect(block).topLeft() # Check if the position of the block is out side of the visible # area. if position.y() > page_bottom: break # We want the line number for the selected line to be bold. bold = False if block == current_block: bold = True font = painter.font() font.setBold(True) painter.setFont(font) # Draw the line number right justified at the y position of the # line. 3 is a magic padding number. drawText(x, y, text). x = self.width() - font_metrics.width(str(line_count)) - 3 y = round(position.y()) - contents_y + font_metrics.ascent() t = str(line_count) painter.drawText(x, y, t) # Remove the bold style if it was set previously. if bold: font = painter.font() font.setBold(False) painter.setFont(font) block = block.next() self.highest_line = line_count painter.end() QWidget.paintEvent(self, event)
def paintEvent(self, event=None): font = QFont(self.font()) font.setPointSize(font.pointSize() - 1) fm = QFontMetricsF(font) fracWidth = fm.width(FractionSlider.WSTRING) indent = fm.boundingRect("9").width() / 2.0 if not X11: fracWidth *= 1.5 span = self.width() - (FractionSlider.XMARGIN * 2) value = self.__numerator / float(self.__denominator) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QPainter.TextAntialiasing) painter.setPen(self.palette().color(QPalette.Mid)) painter.setBrush(self.palette().brush( QPalette.AlternateBase)) painter.drawRect(self.rect()) segColor = QColor(Qt.green).dark(120) segLineColor = segColor.dark() painter.setPen(segLineColor) painter.setBrush(segColor) painter.drawRect(FractionSlider.XMARGIN, FractionSlider.YMARGIN, span, fm.height()) textColor = self.palette().color(QPalette.Text) segWidth = span / self.__denominator segHeight = fm.height() * 2 nRect = fm.boundingRect(FractionSlider.WSTRING) x = FractionSlider.XMARGIN yOffset = segHeight + fm.height() for i in range(self.__denominator + 1): painter.setPen(segLineColor) painter.drawLine(x, FractionSlider.YMARGIN, x, segHeight) painter.setPen(textColor) y = segHeight rect = QRectF(nRect) rect.moveCenter(QPointF(x, y + fm.height() / 2.0)) painter.drawText(rect, Qt.AlignCenter, QString.number(i)) y = yOffset rect.moveCenter(QPointF(x, y + fm.height() / 2.0)) painter.drawText(rect, Qt.AlignCenter, QString.number(self.__denominator)) painter.drawLine(QPointF(rect.left() + indent, y), QPointF(rect.right() - indent, y)) x += segWidth span = int(span) y = FractionSlider.YMARGIN - 0.5 triangle = [QPointF(value * span, y), QPointF((value * span) + (2 * FractionSlider.XMARGIN), y), QPointF((value * span) + FractionSlider.XMARGIN, fm.height())] painter.setPen(Qt.yellow) painter.setBrush(Qt.darkYellow) painter.drawPolygon(QPolygonF(triangle))
def sliceImg(width, height, axisLabels, perpAxisLabel, perpAxisValue): print perpAxisLabel, perpAxisValue img = QImage(width, height, QImage.Format_ARGB32) img.fill(0) p = QPainter(img) p.setPen(QColor(255, 255, 255)) p.setBrush(QBrush(QColor(255, 255, 255))) def arrow(p, From, To, label): p.drawLine(From, To) p.drawText(To, label) offset = 10 arrow(p, QPoint(offset, offset), QPoint(offset, height - offset), axisLabels[1]) arrow(p, QPoint(offset, offset), QPoint(width - offset, offset), axisLabels[0]) p.drawText(2 * offset, 2 * offset, "%s=%d" % (perpAxisLabel, perpAxisValue)) fm = p.fontMetrics() size = fm.size(Qt.TextSingleLine, "updown") p.drawText(numpy.random.randint(offset, width - offset - size.width()), numpy.random.randint(offset, height - offset - size.height()), "updown") dots = [] numPixels = 0 while numPixels < 30: r = numpy.random.randint(1, 255) rx, ry = numpy.random.randint(offset, width - offset), numpy.random.randint( offset, height - offset) if img.pixel(rx, ry) != 0: continue p.setPen(QPen(QColor(r, r, r))) p.drawPoint(rx, ry) dots.append(((rx, ry), r)) numPixels += 1 p.end() img.save('test.png') a = qimage2ndarray.rgb_view(img) a = a[:, :, 0].squeeze().swapaxes(0, 1) for (rx, ry), r in dots: assert QColor.fromRgba(img.pixel(rx, ry)).red( ) == r, "QColor.fromRgba(img.pixel(rx,ry)).red() == %d != %d" % ( QColor.fromRgba(img.pixel(rx, ry)).red(), r) assert (a[rx, ry] == r), "a[%d,%d] == %d != %d)" % (rx, ry, a[rx, ry], r) return (a, dots)
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.fillRect(event.rect(), QBrush(Qt.white)) size = min(self.width(), self.height()) painter.setViewport(self.width() / 2 - size / 2, self.height() / 2 - size / 2, size, size) painter.setWindow(0, 0, 100, 100) painter.drawText(10, 10, 80, 80, Qt.AlignCenter, "Python") painter.end()
def paintEvent(self, event): """ Overloads the paint event to paint additional \ hint information if no text is set on the \ editor. :param event | <QPaintEvent> """ super(XLineEdit, self).paintEvent(event) # paint the hint text if not text is set if self.text() and not (self.icon() and not self.icon().isNull()): return # paint the hint text painter = QPainter(self) painter.setPen(self.hintColor()) icon = self.icon() left, top, right, bottom = self.getTextMargins() w = self.width() h = self.height() - 2 w -= (right + left) h -= (bottom + top) if icon and not icon.isNull(): size = icon.actualSize(self.iconSize()) x = 5 + left y = (self.height() - size.height()) / 2.0 painter.drawPixmap(x, y, icon.pixmap(size.width(), size.height())) w -= size.width() - 2 else: x = 6 + left w -= sum([btn.width() for btn in self.buttons()]) y = 2 + top # create the elided hint if not self.text() and self.hint(): rect = self.cursorRect() metrics = QFontMetrics(self.font()) hint = metrics.elidedText(self.hint(), Qt.ElideRight, w) align = self.alignment() if align & Qt.AlignHCenter: x = 0 else: x = rect.center().x() painter.drawText(x, y, w, h, align, hint)
def paintEvent(self, event): painter = QPainter(self) rect = self.geometry() text_rect = QRect(0, 0, rect.width(), rect.height()) painter.translate(text_rect.bottomLeft()) painter.rotate(-90) painter.drawText( QRect(QPoint(0, 0), QSize(rect.height(), rect.width())), Qt.AlignCenter, self.text()) painter.end()
def paintEvent(self, event): w, h, cx, cy, r = self.clockFaceDetails() painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.fillRect(event.rect(), self.background) painter.setBrush(QBrush(Qt.NoBrush)) painter.setPen(QPen(Qt.black)) painter.drawEllipse(cx - r * 1.1, cy - r * 1.1, 2.2 * r, 2.2 * r) painter.setBrush(QBrush(Qt.NoBrush)) painter.setPen(QPen(Qt.black, 3)) for i in range(12): angle = 2 * i * math.pi / 12 painter.drawLine(cx + (0.9 * r * math.cos(angle)), cy + (0.9 * r * math.sin(angle)), cx + (r * math.cos(angle)), cy + (r * math.sin(angle))) painter.setPen(QPen(Qt.black, 2)) for i in range(60): angle = 2 * i * math.pi / 60 painter.drawLine(cx + (0.95 * r * math.cos(angle)), cy + (0.95 * r * math.sin(angle)), cx + (r * math.cos(angle)), cy + (r * math.sin(angle))) hour, minute = self.displayTime hour = hour % 12 angle = (-math.pi / 2) + (2 * hour * math.pi / 12) + (2 * math.pi / 12 * minute / 60.0) painter.setPen(QPen(Qt.black, 8, Qt.SolidLine, Qt.RoundCap)) painter.drawLine(cx, cy, cx + (0.55 * r * math.cos(angle)), cy + (0.55 * r * math.sin(angle))) angle = (-math.pi / 2) + (2 * minute * math.pi / 60) painter.drawLine(cx, cy, cx + (0.8 * r * math.cos(angle)), cy + (0.8 * r * math.sin(angle))) painter.setPen(QPen(self.foreground)) painter.setFont(self.font()) rect = QRect(0, self.height() * 0.75, self.width(), self.maxHeight) painter.drawText(rect, Qt.AlignCenter, "%02i:%02i" % self.displayTime) painter.end()
def paintEvent(self, event): super(DetailedProgress, self).paintEvent(event) if not self._current_progress: return painter = QPainter(self) width = self.width() height = self.height() aspect_ratio = float(width) / height nr_realizations = max([iens for iens, _ in self._current_progress]) + 1 fm_size = max( [len(progress) for _, progress in self._current_progress]) self.grid_height = math.ceil(math.sqrt(nr_realizations / aspect_ratio)) self.grid_width = math.ceil(self.grid_height * aspect_ratio) sub_grid_size = math.ceil(math.sqrt(fm_size)) cell_height = height / self.grid_height cell_width = width / self.grid_width foreground_image = QImage(self.grid_width * sub_grid_size, self.grid_height * sub_grid_size, QImage.Format_ARGB32) foreground_image.fill(QColor(0, 0, 0, 0)) for index, (iens, progress) in enumerate(self._current_progress): y = int(iens / self.grid_width) x = int(iens - (y * self.grid_width)) self.draw_window(x * sub_grid_size, y * sub_grid_size, progress, foreground_image) painter.drawImage(self.contentsRect(), foreground_image) for index, (iens, progress) in enumerate(self._current_progress): y = int(iens / self.grid_width) x = int(iens - (y * self.grid_width)) painter.setPen(QColor(80, 80, 80)) painter.drawText(x * cell_width, y * cell_height, cell_width, cell_height, Qt.AlignHCenter | Qt.AlignVCenter, str(iens)) if iens == self.selected_realization: pen = QPen(QColor(240, 240, 240)) elif (self.has_realization_failed(progress)): pen = QPen(QColor(*self.state_colors['Failure'])) else: pen = QPen(QColor(80, 80, 80)) thickness = 4 pen.setWidth(thickness) painter.setPen(pen) painter.drawRect((x * cell_width) + (thickness / 2), (y * cell_height) + (thickness / 2), cell_width - (thickness - 1), cell_height - (thickness - 1))
def paintEvent(self, event): painter = QPainter(self) font_metrics = QFontMetrics(self.font()) if font_metrics.width(self.text()) > self.contentsRect().width(): label_width = self.size().width() gradient = QLinearGradient(0, 0, label_width, 0) gradient.setColorAt(1 - 50.0 / label_width, self.palette().color(self.foregroundRole())) gradient.setColorAt(1.0, Qt.transparent) painter.setPen(QPen(QBrush(gradient), 1.0)) painter.drawText(self.contentsRect(), Qt.TextSingleLine | int(self.alignment()), self.text())
def paintEvent(self, event): QLineEdit.paintEvent(self, event) if not self.hasFocus() and not self.text() and self.inactiveText: options = QStyleOptionFrameV2() self.initStyleOption(options) text_rect = self.style().subElementRect(QStyle.SE_LineEditContents, options, self) text_rect.adjust(self.left_margin + 2, 0, -self.right_margin, 0) painter = QPainter(self) painter.setPen(self.palette().brush(QPalette.Disabled, QPalette.Text).color()) painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter, self.inactiveText)
def paintEvent(self, event): """ Draw the QImage on screen. """ textPosX,textPosY = 10,200 painter = QPainter(self) painter.drawImage(painter.viewport(), self._image) innerFont = QFont() innerFont.setPointSize(12) painter.setFont(innerFont) painter.setPen(QColor(QtCore.Qt.white)) painter.drawText(10,180,'Current Action:') painter.drawText(10,200,self._currentMovement) self.drawMoreText(painter,10,300,['Control Buttons:', 'w,s - Walking Forwards/Backwards', 'q,e - Walking Left/Right', 'a,d - Turning Left/Right', 'x - stopping', 'Space - standing up', 'Ctrl - crouch', 'Escape,Enter - restMode, wakeUp', '1 - Grabbing small', '2 - Grabbing large', '3 - Grabbing Kuscheltier', '4 - Grabbing bottle']) self.drawMoreText(painter,self.width()-300-25,300,['Dialog Control:({})'.format(self._attitude), 'u - Introduction', 'i - Ask for object', 'h - Object is Somat', 'j - Object is Muesli', 'k - Object is Bottle', 'l - Object is Kuscheltier', 'n - Wertstoff', 'm - Altpapier', 'o - Ask for help', 'z - Ask proband to repeat sentence', 'p - Repeat task', '0(Null) - construct initial state', 't - Goodbye', 'b - thanks', '# - Start free Speech(PopUp)']) self.drawMoreText(painter,100,50,['Movement Speeds','Forward: {}'.format(self._currentSpeeds['Forward']),'Leftward: {}'.format(self._currentSpeeds['Leftward']),'CounterClockwise: {}'.format(self._currentSpeeds['CounterClockwise'])]) pen = QPen() pen.setColor(QColor(QtCore.Qt.red)) pen.setWidth(5) painter.setPen(pen) painter.drawEllipse(20,15,60,30) pen.setColor(QColor(QtCore.Qt.blue)) painter.setPen(pen) painter.drawPolygon(self.rotatePolygon(arrowPolygon,math.degrees(self._motionProxy.getAngles('HeadYaw',True)[0]),[30,20]))
def _paint_title(self, p: QPainter): p.drawLine(Block.padding, 35 + Block.padding, self.width() - Block.padding, 35 + Block.padding) p.setPen(self._fg_color) f = p.font() f.setPointSize(10) f.setBold(True) p.setFont(f) p.drawText(QRectF(4 + Block.padding, Block.padding + 2, self.width() - 12, 25), str(self.settings["Name"].value())) f.setBold(False) f.setPointSize(8) p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 100)) p.setFont(f) p.drawText(QRectF(4 + Block.padding, 18 + Block.padding, self.width() - 12, 15), str(self.__type_name))
def paintEvent(self, event): contents_y = 0 page_bottom = self.edit.viewport().height() font_metrics = QFontMetrics(self.edit.document().defaultFont()) current_block = self.edit.document().findBlock( self.edit.textCursor().position()) painter = QPainter(self) painter.fillRect(self.rect(), Qt.lightGray) block = self.edit.firstVisibleBlock() viewport_offset = self.edit.contentOffset() line_count = block.blockNumber() painter.setFont(self.edit.document().defaultFont()) while block.isValid(): line_count += 1 # The top left position of the block in the document position = self.edit.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 # We want the line number for the selected line to be bold. bold = False if block == current_block: bold = True font = painter.font() font.setBold(True) painter.setFont(font) # Draw the line number right justified at the y position of the # line. 3 is a magic padding number. drawText(x, y, text). painter.drawText( self.width() - font_metrics.width(str(line_count)) - 3, round(position.y()) + font_metrics.ascent() + font_metrics.descent() - 1, str(line_count)) # Remove the bold style if it was set previously. if bold: font = painter.font() font.setBold(False) painter.setFont(font) block = block.next() self.highest_line = line_count painter.end() QWidget.paintEvent(self, event)
def paintEvent(self, *args, **kwargs): painter = QPainter(self) painter.drawPixmap(0, 0, 12, self.WIDTH_BORDER_TOP, self.__pic_bg, 0, 0, 12, self.WIDTH_BORDER_TOP) painter.drawPixmap( self.WIDTH_BORDER_LEFT, 0, self.width() - self.WIDTH_BORDER_RIGHT - self.WIDTH_BORDER_LEFT, self.WIDTH_BORDER_TOP, self.__pic_bg, 12, 0, 1, self.WIDTH_BORDER_TOP) painter.drawPixmap(self.width() - self.WIDTH_BORDER_RIGHT, 0, self.__pic_bg, 13, 0, 12, self.WIDTH_BORDER_TOP) painter.drawPixmap(0, self.height() - self.WIDTH_BORDER_BOTTOM, self.__pic_bg, 0, 90, 12, 14) painter.drawPixmap( 0, self.WIDTH_BORDER_TOP, self.WIDTH_BORDER_LEFT, self.height() - self.WIDTH_BORDER_BOTTOM - self.WIDTH_BORDER_TOP, self.__pic_bg, 0, 89, 12, 1) painter.drawPixmap( self.width() - self.WIDTH_BORDER_RIGHT, self.WIDTH_BORDER_TOP, self.WIDTH_BORDER_LEFT, self.height() - self.WIDTH_BORDER_BOTTOM - self.WIDTH_BORDER_TOP, self.__pic_bg, 13, 89, 12, 1) painter.drawPixmap( self.WIDTH_BORDER_LEFT, self.height() - self.WIDTH_BORDER_BOTTOM, self.width() - self.WIDTH_BORDER_RIGHT - self.WIDTH_BORDER_LEFT, self.WIDTH_BORDER_BOTTOM, self.__pic_bg, 12, 90, 1, 14) painter.drawPixmap(self.width() - self.WIDTH_BORDER_RIGHT, self.height() - self.WIDTH_BORDER_BOTTOM, self.__pic_bg, 13, 90, 12, 14) painter.fillRect( self.WIDTH_BORDER_LEFT - 4, self.WIDTH_BORDER_TOP, self.width() - self.WIDTH_BORDER_LEFT - self.WIDTH_BORDER_RIGHT + 8, self.height() - self.WIDTH_BORDER_BOTTOM - self.WIDTH_BORDER_TOP, QBrush(QColor(255, 255, 255))) painter.setFont(QFont('Microsoft Yahei', 8, QFont.Bold)) painter.setPen(QColor(250, 250, 250, 220)) painter.drawText(1, 5, self.width(), 27, Qt.AlignHCenter | Qt.AlignVCenter, self.windowTitle()) painter.setPen(QColor(50, 50, 50, 255)) painter.drawText(0, 4, self.width(), 27, Qt.AlignHCenter | Qt.AlignVCenter, self.windowTitle()) painter.setPen(QColor(142, 142, 142, 255)) if self.width() > 380: painter.drawLine(self.WIDTH_FRAME_LEFT + self.OFFSET_BORDER_LEFT, self.OFFSET_BORDER_TOP + 22, self.WIDTH_FRAME_LEFT + self.OFFSET_BORDER_LEFT, self.height() - self.OFFSET_BORDER_BOTTOM - 1)
def _paint_content(self, p: QPainter): t = self.settings["Value"].type() p.setPen(self._fg_color) f = self.font() f.setPointSize(9) p.setFont(f) p.drawText(QRectF(Block.padding + 5, self.height() / 2 + 10, self.width() - Block.padding * 2 - 10, 30), Qt.AlignCenter, str(t)) f.setPointSize(12) p.setFont(f) s = 'None' if self.settings["Value"].data() is not None: s = str(self.settings["Value"].data()) p.drawText(QRectF(Block.padding + 5, self.height() / 2 - 5, self.width() - Block.padding * 2 - 10, 30), Qt.AlignCenter, s)
def paintEvent(self, event): QLineEdit.paintEvent(self, event) if not bool(self.text()) and self.inactiveText and not self.hasFocus(): panel = QStyleOptionFrameV2() self.initStyleOption(panel) textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self) leftMargin = 2 rightMargin = self._clearButton.iconSize().width() textRect.adjust(leftMargin, 0, -rightMargin, 0) painter = QPainter(self) disabledColor = self.palette().brush(QPalette.Disabled, QPalette.Text).color() painter.setPen(disabledColor) painter.drawText(textRect, Qt.AlignLeft | Qt.AlignVCenter, self.inactiveText)
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, True) painter.fillRect(self.contentsRect(), Qt.lightGray) self.paint_tiles(painter) self.paint_pieces(painter) self.paint_names(painter) self.paint_buttons(painter) painter.setPen(QPen(Qt.black, 8)) font = QFont() font.setPointSize(20) painter.setFont(font) if get_player() == "W": painter.setPen(QPen(Qt.white, 8)) painter.drawText(QRectF(10, 10, 60, 60), Qt.AlignCenter, get_player())
def create_major_ticks_labels(self): """ Draw major ticks labels """ painter = QPainter(self) # painter.setRenderHint(QPainter.HighQualityAntialiasing) painter.setRenderHint(QPainter.Antialiasing) # Koordinatenursprung in die Mitte der Flaeche legen painter.translate(*self.center_p()) # painter.save() font = QFont(self.scale_fontname, self.scale_fontsize) fm = QFontMetrics(font) pen_shadow = QPen() pen_shadow.setBrush(self.ScaleValueColor) painter.setPen(pen_shadow) # Scale ticks relative radius text_radius_factor = 0.75 text_radius = self.widget_diameter / 2 * text_radius_factor scale_per_div = int( (self.value_max - self.value_min) / self.scala_main_count) angle_distance = (float(self.scale_angle_size) / float(self.scala_main_count)) for i in range(self.scala_main_count + 1): # text = str(int((self.value_max - self.value_min) / self.scala_main_count * i)) text = str(int(self.value_min + scale_per_div * i)) w = fm.width(text) + 1 h = fm.height() painter.setFont(QFont(self.scale_fontname, self.scale_fontsize)) angle = angle_distance * i + float(self.scale_angle_start_value - self.angle_offset) x = text_radius * math.cos(math.radians(angle)) y = text_radius * math.sin(math.radians(angle)) # print(w, h, x, y, text) text = [ x - int(w / 2), y - int(h / 2), int(w), int(h), Qt.AlignCenter, text ] painter.drawText(text[0], text[1], text[2], text[3], text[4], text[5])
def create_digital_indicator(self): """ Main value indicator inside the Gauge """ painter = QPainter(self) # painter.setRenderHint(QPainter.HighQualityAntialiasing) painter.setRenderHint(QPainter.Antialiasing) # Koordinatenursprung in die Mitte der Flaeche legen # Place the coordinate origin in the center painter.translate(*self.center_p()) # painter.save() # xShadow = 3.0 # yShadow = 3.0 font = QFont(self.value_fontname, self.value_fontsize) fm = QFontMetrics(font) pen_shadow = QPen() pen_shadow.setBrush(self.DisplayValueColor) painter.setPen(pen_shadow) text_radius = self.widget_diameter / 2 * self.text_radius_factor # angle_distance = (float(self.scale_angle_size) / float(self.scala_main_count)) # for i in range(self.scala_main_count + 1): text = str(int(self.value)) w = fm.width(text) + 1 h = fm.height() painter.setFont(QFont(self.value_fontname, self.value_fontsize)) # Mitte zwischen Skalenstart und Skalenende: # Skalenende = Skalenanfang - 360 + Skalenlaenge # Skalenmitte = (Skalenende - Skalenanfang) / 2 + Skalenanfang angle_end = float(self.scale_angle_start_value + self.scale_angle_size - 360) angle = (angle_end - self.scale_angle_start_value ) / 2 + self.scale_angle_start_value x = text_radius * math.cos(math.radians(angle)) y = text_radius * math.sin(math.radians(angle)) # print(w, h, x, y, text) text = [ x - int(w / 2), y - int(h / 2), int(w), int(h), Qt.AlignCenter, text ] painter.drawText(text[0], text[1], text[2], text[3], text[4], text[5])
def run_script(iface): canvas = iface.mapCanvas() img = QImage(QSize(1920, 1080), QImage.Format_ARGB32_Premultiplied) color = QColor(255, 255, 255) p = QPainter(img) for path in paths: #accessibilityLayer.setDataProvider(path) # http://www.qgisworkshop.org/html/workshop/python_in_qgis_tutorial2.html rlayer = iface.addRasterLayer(path) # http://gis.stackexchange.com/questions/26846 rlayer.loadNamedStyle( '/home/matthewc/microaccessibility/times/colors.qml') # add the vector layers poly = iface.addVectorLayer( 'dbname=\'matthewc\' host=localhost port=5432 user=\'matthewc\' password=\'password\' sslmode=disable key=\'tid\' srid=4326 type=POLYGON table="public"."ucsb_final_polygon" (way) sql=', 'poly', 'postgres') poly.loadNamedStyle('/home/matthewc/microaccessibility/times/poly.qml') line = iface.addVectorLayer( 'dbname=\'matthewc\' host=localhost port=5432 user=\'matthewc\' password=\'password\' sslmode=disable key=\'tid\' srid=4326 type=LINESTRING table="public"."ucsb_final_line" (way) sql=', 'line', 'postgres') line.loadNamedStyle('/home/matthewc/microaccessibility/times/line.qml') renderer = canvas.mapRenderer() img.fill(color.rgb()) p.begin(img) p.setRenderHint(QPainter.Antialiasing) renderer.setOutputSize(img.size(), img.logicalDpiX()) renderer.render(p) p.setFont(QFont("Ubuntu", 48, QFont.Bold)) p.setPen(QColor(0, 0, 0)) p.drawText(10, 58, parseToTime(path)) p.end() img.save(path + ".png", "png") QgsMapLayerRegistry.instance().removeMapLayer(rlayer.id()) QgsMapLayerRegistry.instance().removeMapLayer(poly.id()) QgsMapLayerRegistry.instance().removeMapLayer(line.id())
def drawBaseImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset): if self._image == None or not self.lastBackgroundImage == backgroundImage: self.lastBackgroundImage = backgroundImage if backgroundImage == "": im = Image.new("RGB", (1280, 720), "black") else: im = Image.open(backgroundImage) # resize if necessary if not im.size == (1280, 720): im = im.resize((1280, 720), Image.ANTIALIAS) self._image = ImageQt(im) self._image1 = QtGui.QImage(self._image) painter = QPainter(self._image1) font = titleFont font.setPointSizeF(fontSize) painter.setFont(font) painter.setPen(QColor(255, 255, 255)) yPosition = yOffset fm = QtGui.QFontMetrics(font) if alignment == 0: #Left xPosition = xOffset if alignment == 1: #Middle xPosition = xOffset - fm.width(titleText) / 2 if alignment == 2: #Right xPosition = xOffset - fm.width(titleText) painter.drawText(xPosition, yPosition, titleText) painter.end() buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.ReadWrite) self._image1.save(buffer, "PNG") strio = io.BytesIO() strio.write(buffer.data()) buffer.close() strio.seek(0) return Image.open(strio)
def paintEvent(self, event): QWidget.paintEvent(self, event) pen = QPen() pen.setWidth(2) pen.setColor(QColor(200, 200, 200)) rect = self.rect() rect = rect.adjusted(0, 0, -1, -1) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, True) painter.setPen(pen) painter.setOpacity(0.5) painter.setBrush(QBrush(QColor(Qt.white))) painter.drawRoundedRect(rect, 15, 15) painter.setOpacity(1) pen.setColor(Qt.black) painter.setPen(pen) text = self.name + "\n" + self.description painter.drawText(self.rect(), Qt.AlignHCenter | Qt.AlignVCenter, text)
def paintEvent( self, evt ): """ Paint event handler """ QLineEdit.paintEvent( self, evt ) if self.text() == "" and \ self.__inactiveText != "" and \ not self.hasFocus(): panel = QStyleOptionFrameV2() self.initStyleOption( panel ) textRect = self.style().subElementRect( QStyle.SE_LineEditContents, panel, self ) textRect.adjust( 2, 0, 0, 0 ) painter = QPainter( self ) painter.setPen( self.palette().brush( QPalette.Disabled, QPalette.Text ).color() ) painter.drawText( textRect, Qt.AlignLeft | Qt.AlignVCenter, self.__inactiveText ) return
def paintEvent(self, ev): rect = ev.rect() s = self._square rows = range(rect.top() // s, rect.bottom() // s + 1) cols = range(rect.left() // s, rect.right() // s + 1) painter = QPainter(self) painter.setPen(QPen(self.palette().color(QPalette.Window))) painter.setFont(self._font) metrics = QFontMetrics(self._font) # draw characters on white tiles tile = self.palette().color(QPalette.Base) selected_tile = self.palette().color(QPalette.Highlight) selected_tile.setAlpha(96) selected_box = self.palette().color(QPalette.Highlight) text_pen = QPen(self.palette().text()) disabled_pen = QPen(self.palette().color(QPalette.Disabled, QPalette.Text)) selection_pen = QPen(selected_box) for row in rows: for col in cols: char = row * self._column_count + col + self._range[0] if char > self._range[1]: break printable = self.isprint(char) painter.setClipRect(col * s, row * s, s, s) if char == self._selected: painter.fillRect(col * s + 1, row * s + 1, s - 2, s - 2, selected_tile) painter.setPen(selection_pen) painter.drawRect(col * s, row * s, s - 1, s - 1) elif printable: painter.fillRect(col * s + 1, row * s + 1, s - 2, s - 2, tile) painter.setPen(text_pen if printable else disabled_pen) t = chr(char) x = col * s + s // 2 - metrics.width(t) // 2 y = row * s + 4 + metrics.ascent() painter.drawText(x, y, t) else: continue break
def paintEvent(self, event): if not self.image: return p = QPainter(self) ers, sorig = event.rect().size(), self.image.size() img_scaled = self.image.scaled(ers, Qt.KeepAspectRatio) p.drawImage(QPoint(0, 0), img_scaled) p.setRenderHint(QPainter.Antialiasing) p.setPen(Qt.green) p.drawText(10, 20, self.fullpath) p.drawText(10, 40, '#annotations: {}'.format(len(self.polylines))) sx = float(img_scaled.size().width()) / sorig.width() sy = float(img_scaled.size().height()) / sorig.height() p.scale(sx, sy) p.setPen(Qt.yellow) for polyline in self.polylines: self._draw_polyline(p, polyline)
def createPixmap(width=128, height=128, text=None): """ This definition create a default `QPixmap <http://doc.qt.nokia.com/qpixmap.html>`_ instance. :param width: Pixmap width. ( Integer ) :param height: Pixmap height. ( Integer ) :param text: Pximap text. ( String ) :return: QPixmap. ( QPixmap ) """ loadingPixmap = QPixmap(width, height) loadingPixmap.fill(QColor(96, 96, 96)) painter = QPainter(loadingPixmap) if text: painter.setPen(QPen(QColor(192, 192, 192))) pointX = painter.fontMetrics().width(text) / 2 pointY = width / 2 painter.drawText(pointX, pointY, text) return loadingPixmap
def paintEvent(self, event): painter = QPainter(self) btnRect = self.geometry() iconRect = self.iconSize() color = QColor(Qt.black) if self.hovered: color = self.color if self.pressed: color = self.color.darker(120) painter.setPen(QPen(QColor(Qt.lightGray), 2)) outline = QPainterPath() outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0) painter.setOpacity(1) painter.drawPath(outline) painter.setBrush(QBrush(color)) painter.setOpacity(self.opacity) painter_path = QPainterPath() painter_path.addRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0) if self.hovered: painter.setClipPath(painter_path) painter.drawRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0) painter.setOpacity(1) iconPos, textPos = self.calIconTextPos(btnRect, iconRect) # 重画文本 if not self.text().isNull(): painter.setFont(self.font()) painter.setPen(QPen(QColor(Qt.black), 2)) painter.drawText(textPos.x(), textPos.y(), textPos.width(), textPos.height(), Qt.AlignCenter, self.text()) # 重画图标 if not self.icon().isNull(): painter.drawPixmap(iconPos, QPixmap(self.icon().pixmap(self.iconSize())))
def lineNumberAreaPaintEvent(self, event): painter = QPainter(self.lineNumberArea) painter.fillRect(event.rect(), Qt.lightGray) block = self.firstVisibleBlock() blockNumber = block.blockNumber() top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top() bottom = top + self.blockBoundingRect(block).height() while (block.isValid() and top <= event.rect().bottom()): if (block.isVisible() and bottom >= event.rect().top()): number = QString.number(blockNumber + 1) painter.setPen(Qt.black) painter.drawText(0, top, self.lineNumberArea.width(), self.fontMetrics().height(), Qt.AlignRight, number) block = block.next() top = bottom bottom = top + self.blockBoundingRect(block).height() blockNumber += 1
def paintEvent(self, ev): edit = self._textedit if not edit: return painter = QPainter(self) painter.setFont(edit.font()) rect = QRect(0, 0, self.width() - 2, QFontMetrics(edit.font()).height()) block = edit.firstVisibleBlock() while block.isValid(): geom = edit.blockBoundingGeometry(block) geom.translate(edit.contentOffset()) if geom.top() >= ev.rect().bottom(): break if block.isVisible() and geom.bottom() > ev.rect().top() + 1: rect.moveTop(geom.top()) text = format(block.blockNumber() + 1, 'd') painter.drawText(rect, Qt.AlignRight, text) block = block.next()
def paintEvent(self, event ): """QLineEdit.paintEvent implementation. Draws prompt """ QLineEdit.paintEvent( self, event ) if self._promptText and not self.text() and self.isEnabled() : option = QStyleOptionFrameV3() self.initStyleOption( option ) left, top, right, bottom = self.getTextMargins() va = self.style().visualAlignment( self.layoutDirection(), self.alignment() ) rect = self.style().subElementRect( QStyle.SE_LineEditContents, option, self ).adjusted( 2, 0, 0, 0 ).adjusted( left, top, -right, -bottom ) fm = QFontMetrics ( self.font() ) text = fm.elidedText( self._promptText, Qt.ElideRight, rect.width() ) painter = QPainter ( self ) painter.setPen( self.palette().color( QPalette.Disabled, QPalette.Text ) ) painter.drawText( rect, va, text )