def paintEvent(self, event): super(DragDoubleSpinBoxLine, self).paintEvent(event) p = QPainter() p.begin(self) try: v = float(self.text()) except Exception: v = 0.0000001 try: v /= self._max if v > 0 else (self._min * -1) except Exception: pass if self._sup: p.fillRect(QRect(0, self.height() - 4, v * self.width(), 4), self._color) else: p.fillRect( QRect(self.width() * 0.5, self.height() - 4, v * self.width() * 0.5, 4), self._color if v > 0 else QColor(255, 0, 0)) p.end()
def overlay_pixmap(pixmap, over_pixmap, overlay_color, align=Qt.AlignCenter): """ Overlays one pixmap over the other :param pixmap: :param over_pixmap: :param overlay_color: :param align: :return: """ if isinstance(overlay_color, str): overlay_color = color.Color.from_string(overlay_color) if overlay_color is not None: over_pixmap = colorize_pixmap(over_pixmap, overlay_color) painter = QPainter(pixmap) painter.setCompositionMode(QPainter.CompositionMode_SourceOver) x = 0 y = 0 if align is Qt.AlignCenter: x = pixmap.width() / 2 - over_pixmap.width() / 2 y = pixmap.height() / 2 - over_pixmap.height() / 2 elif align is None: x = 0 y = 0 painter.drawPixmap(x, y, over_pixmap.width(), over_pixmap.height(), over_pixmap) painter.end()
def paintEvent(self, event): if self.isVisible() and self.paintLineNum > 0: # NOTE 更新绘制 self.viewport().update() block = self.firstVisibleBlock() height = self.lineNumberArea.fontMetrics().height() number = block.blockNumber() painter = QPainter(self.viewport()) condition = True while block.isValid() and condition: block_geometry = self.blockBoundingGeometry(block) offset = self.contentOffset() block_top = block_geometry.translated(offset).top() number += 1 block_rect = QRect(0, block_top, self.width(), height) if number == self.paintLineNum: lineColor = QColor(LINE_COLOR).lighter(100) painter.fillRect(block_rect, lineColor) painter.drawRect(block_rect) condition = False if block_top > event.rect().bottom(): condition = False block = block.next() painter.end() return super(CodeEditor, self).paintEvent(event)
def paintEvent(self, event): self.makeCurrent() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glUseProgram(self.shaders_program) gl.glUniform1i(self.colormap_location, 0) gl.glActiveTexture(gl.GL_TEXTURE0 + 0) gl.glBindTexture(gl.GL_TEXTURE_1D, self.colormap_id) gl.glBegin(gl.GL_QUAD_STRIP) bar_start = -1 + self.text_height / self.height() * 2 bar_height = (1 - 2 * self.text_height / self.height()) * 2 steps = 40 for i in range(steps + 1): y = i * (1 / steps) # gl.glColor(y, 0, 0) gl.glVertex(-0.5, (bar_height * y + bar_start), y) gl.glVertex(0.5, (bar_height * y + bar_start), y) gl.glEnd() p = QPainter(self) p.drawText((self.width() - self.vmax_width) / 2, self.text_ascent, self.vmax_str) p.drawText((self.width() - self.vmin_width) / 2, self.height() - self.text_height + self.text_ascent, self.vmin_str) p.end()
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setBrush(QColor(192, 192, 192)) painter.setPen(QColor(64, 64, 64)) painter.drawPolygon(self._arrow) painter.end()
def mousePressEvent(self, event): """ Override the behaviour when the mouse is pressed """ self._drag_initiated = False self._drag_dropped_pos = QPoint() if event.button() == Qt.LeftButton and event.modifiers( ) == Qt.ControlModifier: self._drag_start_pos = event.pos() # Get mouse position and store the area rectangle of the selected tab pos = event.pos() self._select_tab_index = self.tabAt(pos) rect = self.tabRect(self._select_tab_index) # Store a pixmap of the selected tab and a pixmap of the close hand cursor image # After that we draw the tab and also the hand cursor in the middle of the tab pixmap = QPixmap.grabWidget(self, rect) painter = QPainter(pixmap) cursor_pm = QPixmap(':/icons/close_hand_cursor.png') cursor_pos = QPoint(*map(lambda x, y: (x - y) * 0.5, rect.size().toTuple(), cursor_pm.size().toTuple())) painter.drawPixmap(cursor_pos, cursor_pm) painter.end() # Update cursor cursor = QCursor(pixmap) self.setCursor(cursor) super(TearOffTabBar, self).mousePressEvent(event)
def _create_pixmap(self, path, color): """ Internal function that creates a new item pixmap from the given path :param path: str :param color: str or QColor :return: QPixmap """ if not path: return QPixmap() dpi = self.treeWidget().dpi() key = path + color + 'DPI-' + str(dpi) item_pixmap = self._PIXMAP_CACHE.get(key) if not item_pixmap: width = 20 * dpi height = 18 * dpi if '/' not in path and '\\' not in path: path = resources.get('icons', path) if not path or not os.path.exists(path): path = self.default_icon_path() pixmap2 = pixmap.Pixmap(path) pixmap2.set_color(color) pixmap2 = pixmap2.scaled(16 * dpi, 16 * dpi, Qt.KeepAspectRatio, Qt.SmoothTransformation) x = (width - pixmap2.width()) / 2 y = (height - pixmap2.height()) / 2 item_pixmap = QPixmap(QSize(width, height)) item_pixmap.fill(Qt.transparent) painter = QPainter(item_pixmap) painter.drawPixmap(x, y, pixmap2) painter.end() self._PIXMAP_CACHE[key] = item_pixmap return item_pixmap
def set_color(self, new_color, size=None): """ Sets icon color :param new_color: QColor, new color for the icon :param size: QSize, size of the icon """ if isinstance(new_color, str): new_color = color.Color.from_string(new_color) elif isinstance(new_color, (list, tuple)): new_color = color.Color(*new_color) if self.isNull(): return icon = self size = size or icon.availableSizes()[0] pixmap = icon.pixmap(size) painter = QPainter(pixmap) painter.setCompositionMode(QPainter.CompositionMode_SourceIn) painter.setBrush(new_color) painter.setPen(new_color) painter.drawRect(pixmap.rect()) painter.end() icon = Icon(pixmap) self.swap(icon)
def paintEvent(self, event): super(DraggerSlider, self).paintEvent(event) p = QPainter() p.begin(self) p.setPen(color.DARK_GRAY) p.setFont(self._label_font) p.drawText(self.rect(), Qt.AlignCenter, self._label_text) p.end()
def convert_svg_to_bitmap(source, target): svg_renderer = QSvgRenderer(source) height = svg_renderer.defaultSize().height() width = svg_renderer.defaultSize().width() new_image = QImage(width, height, QImage.Format_ARGB32) painter = QPainter(new_image) svg_renderer.render(painter) new_image.save(target) painter.end()
def paintEvent(self, event): """ Overrides base QFrame paintEvent function Override to make mouse events work in transparent widgets :param event: QPaintEvent """ painter = QPainter(self) painter.fillRect(self.rect(), QColor(255, 255, 255, 1)) painter.end()
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.translate(self._loading_pixmap.width() / 2, self._loading_pixmap.height() / 2) painter.rotate(self._rotation) painter.drawPixmap(-self._loading_pixmap.width() / 2, -self._loading_pixmap.height() / 2, self._loading_pixmap.width(), self._loading_pixmap.height(), self._loading_pixmap) painter.end() return super(CircleLoading, self).paintEvent(event)
def overlay_image(front_image, back_image, x, y): """ Overlays front image on top of given background image :param front_image: QImage :param back_image: QImage :param x: int :param y: int """ painter = QPainter(back_image) painter.setRenderHint(QPainter.Antialiasing) painter.drawImage(x, y, front_image) painter.end()
def paintEvent(self, event): """ Override the default paintEvent to add in line numbers. """ vScrollPos = self.textWidget.verticalScrollBar().value() pageBtm = vScrollPos + self.textWidget.viewport().height() currBlock = self.doc.findBlock(self.textWidget.textCursor().position()) fontMetric = self.fontMetrics() painter = QPainter(self) font = painter.font() # Find roughly the current top-most visible block. block = self.doc.begin() lineHeight = self.doc.documentLayout().blockBoundingRect( block).height() block = self.doc.findBlockByNumber(int(vScrollPos / lineHeight)) currLine = block.blockNumber() while block.isValid(): currLine += 1 # Check if the position of the block is outside the visible area. yPos = self.doc.documentLayout().blockBoundingRect( block).topLeft().y() if yPos > pageBtm: break if block == currBlock: # Make the line number for the selected line bold. 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. painter.drawText( self.width() - fontMetric.width(str(currLine)) - 3, round(yPos) - vScrollPos + fontMetric.ascent() + 3, str(currLine)) font.setBold(False) painter.setFont(font) else: painter.drawText( self.width() - fontMetric.width(str(currLine)) - 3, round(yPos) - vScrollPos + fontMetric.ascent() + 3, str(currLine)) # Go to the next block. block = block.next() painter.end() super(LineNumbers, self).paintEvent(event)
def paintEvent(self, event): contents_y = self.editor.verticalScrollBar().value() page_bottom = contents_y + self.editor.viewport().height() font_metrics = self.fontMetrics() current_block = self.editor.document().findBlock( self.editor.textCursor().position()) painter = QPainter(self) line_count = 0 # Iterate over all text blocks in the document block = self.editor.document().begin() font_size = self.editor.font().pointSize() font = painter.font() font.setPixelSize(font_size) offset = font_metrics.ascent() + font_metrics.descent() color = painter.pen().color() painter.setFont(font) align = Qt.AlignRight while block.isValid(): line_count += 1 # Get top left position of the block in the document and check if the position of the block is # outside of the visible area position = self.editor.document().documentLayout( ).blockBoundingRect(block).topLeft() if position.y() == page_bottom: break rect = QRect(0, round(position.y()) - contents_y, self.width() - 5, font_size + offset) # Draw line rect if block == current_block: painter.setPen(Qt.NoPen) painter.setBrush(QBrush(self.bg)) painter.drawRect( QRect(0, round(position.y()) - contents_y, self.width(), font_size + (offset / 2))) painter.setPen(QPen(color)) # Draw text painter.drawText(rect, align, str(line_count)) block = block.next() self.highest_line = line_count painter.end() super(ScriptEditorNumberBar, self).paintEvent(event)
def paintEvent(self, event): # If we call super paintEvent function without an style, the icon will be draw twice if self._style: super(IconButton, self).paintEvent(event) painter = QPainter() painter.begin(self) opt = QStyleOptionButton() self.initStyleOption(opt) rect = opt.rect icon_size = max( min(rect.height(), rect.width()) - 2 * self._pad, self._minSize) opt.iconSize = QSize(icon_size, icon_size) self.style().drawControl(QStyle.CE_PushButton, opt, painter, self) painter.end()
def tint_pixmap(pixmap, tint_color=(255, 255, 255, 100), composition_mode=QPainter.CompositionMode_Plus): """ Composite one pixmap on top of another :param pixmap: :param tint_color: :param composition_mode: :return: """ tint_color = QColor(*tint_color) over_pixmap = QPixmap(pixmap.width(), pixmap.height()) over_pixmap.fill(tint_color) over_pixmap.setMask(pixmap.mask()) painter = QPainter(pixmap) painter.setCompositionMode(composition_mode) painter.drawPixmap(0, 0, over_pixmap.width(), over_pixmap.height(), over_pixmap) painter.end()
def renderNow(self) -> None: if not self.isExposed(): return rect = QRect(0, 0, self.width(), self.height()) self.m_backingStore.beginPaint(QRegion(rect)) device: QPaintDevice = self.m_backingStore.paintDevice() painter = QPainter(device) painter.fillRect(0, 0, self.width(), self.height(), QGradient.NightFade) self.render(painter) painter.end() self.m_backingStore.endPaint() self.m_backingStore.flush(QRegion(rect))
def paintEvent(self, event): if self.isVisible(): block = self.editor.firstVisibleBlock() height = self.fontMetrics().height() number = block.blockNumber() painter = QPainter(self) painter.fillRect(event.rect(), LINEBAR_COLOR) painter.drawRect(event.rect().width() - 1, 0, event.rect().width(), event.rect().height() - 1) font = painter.font() current_block = self.editor.textCursor().block().blockNumber() + 1 condition = True while block.isValid() and condition: block_geometry = self.editor.blockBoundingGeometry(block) offset = self.editor.contentOffset() block_top = block_geometry.translated(offset).top() number += 1 # NOTE set the linebar breakpoint color if self.paintLineNum > 0 and number == self.paintLineNum: font.setBold(True) block_rect = QRect(LINE_MARGIN, block_top, self.width() - LINE_MARGIN * 2, height) painter.fillRect(block_rect, LINEBAR_BP_COLOR) # NOTE set the current line color elif number == current_block: font.setBold(True) block_rect = QRect(LINE_MARGIN, block_top, self.width() - LINE_MARGIN * 2, height) painter.fillRect(block_rect, LINEBAR_NUM_COLOR) else: font.setBold(False) painter.setFont(font) rect = QRect(0, block_top, self.width() - 5, height) painter.drawText(rect, Qt.AlignRight, '%i' % number) if block_top > event.rect().bottom(): condition = False block = block.next() painter.end()
def set_color(self, new_color): """ Sets pixmap's color :param new_color: variant (str || QColor), color to apply to the pixmap """ if isinstance(new_color, str): new_color = color.Color.from_string(new_color) if not self.isNull(): painter = QPainter(self) painter.setCompositionMode(QPainter.CompositionMode_SourceIn) painter.setBrush(new_color) painter.setPen(new_color) painter.drawRect(self.rect()) painter.end() self._color = new_color
def _render_svg(self, svg_path, replace_color=None): if issubclass(self._cls, QIcon) and not replace_color: return QIcon(svg_path) with open(svg_path, 'r+') as f: data_content = f.read() if replace_color is not None: data_content = data_content.replace('#555555', replace_color) self._render.load(QByteArray(data_content)) pix = QPixmap(128, 128) pix.fill(Qt.transparent) painter = QPainter(pix) self._render.render(painter) painter.end() if issubclass(self._cls, QPixmap): return pix else: return self._cls(pix)
def printDocument(self, printer): loop = QEventLoop() result = False def printPreview(success): nonlocal result result = success loop.quit() self.m_page.print(printer, printPreview) loop.exec_() if not result: painter = QPainter() if painter.begin(printer): font = painter.font() font.setPixelSize(20) painter.setFont(font) painter.drawText(QPointF(10, 25), "Could not generate print preview.") painter.end()
def thumbnail_icon(self): """ Returns the thumbnail icon :return: QIcon """ # custom_path = self.custom_icon_path() # if custom_path and '/' not in custom_path and '\\' not in custom_path: # custom_path = resources.icon('icons/{}'.format(self.theme().style()), custom_path) # if not custom_path or not os.path.isfile(custom_path): # return super(FolderItemView, self).thumbnail_icon() return super(FolderItemView, self).thumbnail_icon() color = self.icon_color() if not color: color = consts.DEFAULT_FOLDER_ICON_COLOR icon_key = custom_path + color icon = self._THUMBNAIL_ICON_CACHE.get(icon_key) if not icon: color1 = qt_color.Color.from_string(color) color2 = qt_color.Color.from_string('rgb(255, 255, 255, 150)') pixmap1 = qt_pixmap.Pixmap(self.THUMBNAIL_PATH) pixmap2 = qt_pixmap.Pixmap(custom_path) pixmap1.set_color(color1) pixmap2.set_color(color2) pixmap1 = pixmap1.scaled(128, 128, Qt.KeepAspectRatio, Qt.SmoothTransformation) pixmap2 = pixmap2.scaled(64, 64, Qt.KeepAspectRatio, Qt.SmoothTransformation) x = (128 - pixmap2.width()) / 2 y = (128 - pixmap2.width()) / 2 painter = QPainter(pixmap1) painter.drawPixmap(x, y + 5, pixmap2) painter.end() icon = qt_icon.Icon(pixmap1) self._THUMBNAIL_ICON_CACHE[icon_key] = icon return self._THUMBNAIL_ICON_CACHE.get(icon_key)
def cdMapper(self,*args): global cdR, cdG, cdB temp2 = QPixmap(cd_pix2) mask = QPixmap(cd_pix2_alpha) mult = 255 R = cdR * mult G = cdG *mult B = cdB * mult colour = QColor(R,G,B) #print("R:" + str(cdR) + " G:" + str(cdG) + " B:" + str(cdB)) #Paint Lines painter2 = QPainter(temp2) painter2.setCompositionMode(painter2.CompositionMode_Overlay) painter2.fillRect(temp2.rect(), colour) painter2.end() #Update Image self.main_widget.lbl_LGTC_PRV.setPixmap(temp2)
def paintEvent(self, event): """ Overrides base QToolButton paintEvent function Triggered on frame changed :param event: QEvent """ super(ImageSequenceWidget, self).paintEvent(event) painter = QPainter() painter.begin(self) if self.current_filename() and self._image_sequence.frame_count() > 1: r = event.rect() playhead_height = self.playhead_height() playhead_pos = self._image_sequence.percent() * r.width() - 1 x = r.x() y = self.height() - playhead_height painter.seten(Qt.NoPen) painter.setBrush(QBrush(self.DEFAULT_PLAYHEAD_COLOR)) painter.drawRect(x, y, playhead_pos, playhead_height) painter.end()
def paintEvent(self, event): self.makeCurrent() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glUseProgram(self.shaders_program) gl.glUniform1i(self.colormap_location, 0) gl.glActiveTexture(gl.GL_TEXTURE0 + 0) gl.glBindTexture(gl.GL_TEXTURE_1D, self.colormap_id) gl.glBegin(gl.GL_QUAD_STRIP) bar_start = -1 + self.text_height / self.height() * 2 bar_height = (1 - 2 * self.text_height / self.height()) * 2 steps = 40 for i in range(steps + 1): y = i * (1 / steps) # gl.glColor(y, 0, 0) gl.glVertex(-0.5, (bar_height*y + bar_start), y) gl.glVertex(0.5, (bar_height*y + bar_start), y) gl.glEnd() p = QPainter(self) p.drawText((self.width() - self.vmax_width)/2, self.text_ascent, self.vmax_str) p.drawText((self.width() - self.vmin_width)/2, self.height() - self.text_height + self.text_ascent, self.vmin_str) p.end()
def set_badge(self, x, y, w, h, color=None): """ Set badge for the icon :param x: int :param y: int :param w: int :param h: int :param color: QColor or None """ color = color or QColor(240, 100, 100) size = self.actualSize(QSize(256, 256)) pixmap = self.pixmap(size) painter = QPainter(pixmap) pen = QPen(color) pen.setWidth(0) painter.setPen(pen) painter.setBrush(color) painter.setRenderHint(QPainter.Antialiasing) painter.drawEllipse(x, y, w, h) painter.end() icon = Icon(pixmap) self.swap(icon)
def _setup_general_tab(self): general_widget = QWidget() general_layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 2)) general_widget.setLayout(general_layout) self._themes_combobox = combobox.BaseComboBox(parent=self) all_themes = resources.get_all_resources_of_type( resources.ResourceTypes.THEME) for i, theme in enumerate(all_themes): accent_color_hex = theme.accent_color accent_color = color.Color.hex_to_qcolor( accent_color_hex[1:] if accent_color_hex. startswith('#') else accent_color_hex) background_color_hex = theme.background_color background_color = color.Color.hex_to_qcolor( background_color_hex[1:] if accent_color_hex. startswith('#') else background_color_hex) accent_color_pixmap = QPixmap(25, 25) background_color_pixmap = QPixmap(25, 25) accent_color_pixmap.fill(accent_color) background_color_pixmap.fill(background_color) color_pixmap = QPixmap(50, 25) painter = QPainter(color_pixmap) painter.drawPixmap(0, 0, 25, 25, accent_color_pixmap) painter.drawPixmap(25, 0, 25, 25, background_color_pixmap) painter.end() color_icon = QIcon(color_pixmap) self._themes_combobox.addItem(color_icon, theme.name()) general_layout.addWidget(self._themes_combobox) general_layout.addStretch() return general_widget
def paintEvent(self, event: QPaintEvent) -> None: p = QPainter(self) self.m_normalMap.render(p, event.rect()) p.setPen(Qt.black) p.drawText( self.rect(), Qt.AlignBottom | Qt.TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors", ) p.end() if self.zoomed: dim = min(self.width(), self.height()) magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3) radius = magnifierSize / 2 ring = radius - 15 box = QSize(magnifierSize, magnifierSize) if self.maskPixmap.size() != box: self.maskPixmap = QPixmap(box) self.maskPixmap.fill(Qt.transparent) g = QRadialGradient() g.setCenter(radius, radius) g.setFocalPoint(radius, radius) g.setRadius(radius) g.setColorAt(1.0, QColor(255, 255, 255, 0)) g.setColorAt(0.5, QColor(128, 128, 128, 255)) mask = QPainter(self.maskPixmap) mask.setRenderHint(QPainter.Antialiasing) mask.setCompositionMode(QPainter.CompositionMode_Source) mask.setBrush(g) mask.setPen(Qt.NoPen) mask.drawRect(self.maskPixmap.rect()) mask.setBrush(QColor(Qt.transparent)) mask.drawEllipse(g.center(), ring, ring) mask.end() center = self.dragPos - QPoint(0, radius) center = center + QPoint(0, radius / 2) corner = center - QPoint(radius, radius) xy = center * 2 - QPoint(radius, radius) # only set the dimension to the magnified portion if self.zoomPixmap.size() != box: zoomPixmap = QPixmap(box) zoomPixmap.fill(Qt.lightGray) if True: p = QPainter(zoomPixmap) p.translate(-xy) self.m_largeMap.render(p, QRect(xy, box)) p.end() clipPath = QPainterPath() clipPath.addEllipse(center, ring, ring) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) p.setClipPath(clipPath) p.drawPixmap(corner, zoomPixmap) p.setClipping(False) p.drawPixmap(corner, self.maskPixmap) p.setPen(Qt.gray) p.drawPath(clipPath) if self.invert: p = QPainter(self) p.setCompositionMode(QPainter.CompositionMode_Difference) p.fillRect(event.rect(), Qt.white) p.end()
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setRenderHint(painter.Antialiasing) font = painter.font() font.setBold(True) painter.setFont(font) x = self.rect().x() y = self.rect().y() w = self.rect().width() - 1 h = self.rect().height() - 1 _rect = 8 if self.rollout_style == AccordionStyle.ROUNDED: painter.drawText(x + 33 if not self._icon else 40, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) self._draw_triangle(painter, x, y) self._draw_icon(painter, x + 22, y + 3) pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, _rect, _rect) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRoundedRect(x, y, w - 1, h - 1, _rect, _rect) elif self.rollout_style == AccordionStyle.SQUARE: painter.drawText(x + 33 if not self._icon else 40, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) self._draw_triangle(painter, x, y) self._draw_icon(painter, x + 22, y + 3) pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.3) painter.setPen(pen) painter.drawRect(x + 1, y + 1, w - 1, h - 1) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) elif self.rollout_style == AccordionStyle.MAYA: painter.drawText(x + 33 if not self._icon else 40, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) painter.setRenderHint(QPainter.Antialiasing, False) self._draw_triangle(painter, x, y) self._draw_icon(painter, x + 22, y + 3) header_height = 20 header_rect = QRect(x + 1, y + 1, w - 1, header_height) header_rect_shadow = QRect(x - 1, y - 1, w + 1, header_height + 2) pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.4) painter.setPen(pen) painter.drawRect(header_rect) painter.fillRect(header_rect, QColor(255, 255, 255, 18)) pen.setColor(self.palette().color(QPalette.Dark)) painter.setPen(pen) painter.drawRect(header_rect_shadow) if not self.is_collapsed(): pen = QPen(self.palette().color(QPalette.Dark)) pen.setWidthF(0.8) painter.setPen(pen) offset = header_height + 3 body_rect = QRect(x, y + offset, w, h - offset) body_rect_shadow = QRect(x + 1, y + offset, w + 1, h - offset + 1) painter.drawRect(body_rect) pen.setColor(self.palette().color(QPalette.Light)) pen.setWidth(0.4) painter.setPen(pen) painter.drawRect(body_rect_shadow) elif self.rollout_style == AccordionStyle.BOXED: if self.is_collapsed(): a_rect = QRect(x + 1, y + 9, w - 1, 4) b_rect = QRect(x, y + 8, w - 1, 4) text = '+' else: a_rect = QRect(x + 1, y + 9, w - 1, h - 9) b_rect = QRect(x, y + 8, w - 1, h - 9) text = '-' pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(a_rect) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRect(b_rect) painter.setRenderHint(painter.Antialiasing, False) painter.setBrush(self.palette().color(QPalette.Window).darker(120)) painter.drawRect(x + 10, y + 1, w - 20, 16) painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text) painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title()) if self.drag_drop_mode: rect = self.get_drag_drop_rect() _layout = rect.left() _rect = rect.right() center_y = rect.center().y() for y in (center_y - 3, center_y, center_y + 3): painter.drawLine(_layout, y, _rect, y) painter.end()
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setRenderHint(painter.Antialiasing) font = painter.font() font.setBold(True) painter.setFont(font) x = self.rect().x() y = self.rect().y() w = self.rect().width() - 1 h = self.rect().height() - 1 _rect = 8 if self._rolloutStyle == ExpanderStyles.Rounded: painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) self.__drawTriangle(painter, x, y) pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, _rect, _rect) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRoundedRect(x, y, w - 1, h - 1, _rect, _rect) if self._rolloutStyle == ExpanderStyles.Square: painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) self.__drawTriangle(painter, x, y) pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.2) painter.setPen(pen) painter.drawRect(x + 1, y + 1, w - 1, h - 1) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRect(x, y, w - 1, h - 1) if self._rolloutStyle == ExpanderStyles.Maya: painter.drawText( x + (45 if self.dragDropMode() == ExpanderDragDropModes.InternalMove else 25), y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) painter.setRenderHint(QPainter.Antialiasing, False) self.__drawTriangle(painter, x, y) header_height = 20 header_rect = QRect(x + 1, y + 1, w - 1, header_height) header_rect_shadow = QRect(x - 1, y - 1, w + 1, header_height + 2) pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.4) # painter.setPen(pen) painter.setPen(Qt.NoPen) painter.drawRect(header_rect) painter.fillRect(header_rect, QColor(255, 255, 255, 18)) pen.setColor(self.palette().color(QPalette.Dark)) painter.setPen(pen) painter.drawRect(header_rect_shadow) if not self.isCollapsed(): # pen = QPen(self.palette().color(QPalette.Background)) # painter.setPen(pen) offset = header_height + 3 body_rect = QRect(x, y + offset, w, h - offset) # body_rect_shadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1) painter.drawRect(body_rect) # pen.setColor(self.palette().color(QPalette.Foreground)) # pen.setWidthF(0.4) # painter.setPen(pen) # painter.drawRect(body_rect_shadow) elif self._rolloutStyle == ExpanderStyles.Boxed: if self.isCollapsed(): arect = QRect(x + 1, y + 9, w - 1, 4) brect = QRect(x, y + 8, w - 1, 4) text = '+' else: arect = QRect(x + 1, y + 9, w - 1, h - 9) brect = QRect(x, y + 8, w - 1, h - 9) text = '-' pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(arect) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRect(brect) painter.setRenderHint(painter.Antialiasing, False) painter.setBrush(self.palette().color(QPalette.Window).darker(120)) painter.drawRect(x + 10, y + 1, w - 20, 16) painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text) painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title()) if self.dragDropMode(): rect = self.dragDropRect() _layout = rect.left() _rect = rect.right() center_y = rect.center().y() pen = QPen(self.palette().color(self.isCollapsed() and QPalette.Shadow or QPalette.Mid)) painter.setPen(pen) for y in (center_y - 3, center_y, center_y + 3): painter.drawLine(_layout, y, _rect, y) painter.end()
def paintEvent( self, event ): painter = QPainter() painter.begin(self) painter.setRenderHint(painter.Antialiasing) font = painter.font() font.setBold(True) painter.setFont(font) x = self.rect().x() y = self.rect().y() w = self.rect().width() - 1 h = self.rect().height() - 1 r = 8 # draw a rounded style if self._rolloutStyle == 2: # draw the text painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) # draw the triangle self.__drawTriangle(painter, x, y) # draw the borders pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRoundedRect(x, y, w - 1, h - 1, r, r) # draw a square style if self._rolloutStyle == 3: # draw the text painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) self.__drawTriangle(painter, x, y) # draw the borders pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(x + 1, y + 1, w - 1, h - 1) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRect(x, y, w - 1, h - 1) # draw a Maya style if self._rolloutStyle == 4: # draw the text painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) painter.setRenderHint(QPainter.Antialiasing, False) self.__drawTriangle(painter, x, y) # draw the borders - top headerHeight = 20 headerRect = QRect(x + 1, y + 1, w - 1, headerHeight) headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2) # Highlight pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.4) painter.setPen(pen) painter.drawRect(headerRect) painter.fillRect(headerRect, QColor(255, 255, 255, 18)) # Shadow pen.setColor(self.palette().color(QPalette.Dark)) painter.setPen(pen) painter.drawRect(headerRectShadow) if not self.isCollapsed(): # draw the lover border pen = QPen(self.palette().color(QPalette.Dark)) pen.setWidthF(0.8) painter.setPen(pen) offSet = headerHeight + 3 bodyRect = QRect(x, y + offSet, w, h - offSet) bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1) painter.drawRect(bodyRect) pen.setColor(self.palette().color(QPalette.Light)) pen.setWidthF(0.4) painter.setPen(pen) painter.drawRect(bodyRectShadow) # draw a boxed style elif self._rolloutStyle == 1: if self.isCollapsed(): arect = QRect(x + 1, y + 9, w - 1, 4) brect = QRect(x, y + 8, w - 1, 4) text = '+' else: arect = QRect(x + 1, y + 9, w - 1, h - 9) brect = QRect(x, y + 8, w - 1, h - 9) text = '-' # draw the borders pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(arect) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRect(brect) painter.setRenderHint(painter.Antialiasing, False) painter.setBrush(self.palette().color(QPalette.Window).darker(120)) painter.drawRect(x + 10, y + 1, w - 20, 16) painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text) painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title()) if self.dragDropMode(): rect = self.dragDropRect() # draw the lines l = rect.left() r = rect.right() cy = rect.center().y() for y in (cy - 3, cy, cy + 3): painter.drawLine(l, y, r, y) painter.end()