def paintEvent(self, *args): #TODO OPTIMISE FOR MULTIPLE REPETITIVE CALL super().paintEvent(*args) if self.current_silhouette is not None: # Génération du QPainter print("update started") painter = QPainter(self) # Effacer la pose précédente painter.eraseRect(self.rect()) # get x axis coordonate of the center of the player 1st on the left left_center = self.player_rect.left( ) + 0.5 * self.player_rect.width() - self.player_pixel_spacing * ( len(self.current_silhouette) - 1) * 0.5 n = len(self.current_silhouette) for k in random.sample(range(n), n): vertical_random = self.vertical_random_ratio * self.pose_hauteur * random.random( ) new_pixmap = QPixmap(self.pose_largeur, self.pose_hauteur) new_pixmap.fill(self.colors[k]) new_pixmap.setMask(self.current_silhouette[k].pixmap.scaled( self.pose_largeur, self.pose_hauteur).mask()) painter.drawPixmap( int(left_center + k * self.player_pixel_spacing - (self.pose_largeur * 0.5)), self.player_rect.top() + vertical_random, self.pose_largeur, self.pose_hauteur, new_pixmap)
def paintEvent(self, event): painter = QPainter(self) if self.isChecked(): if self.m_color == self.BLUE: self.m_pixmap.load(":/bitmaps/led_blue.png") elif self.m_color == self.GREEN: self.m_pixmap.load(":/bitmaps/led_green.png") elif self.m_color == self.RED: self.m_pixmap.load(":/bitmaps/led_red.png") elif self.m_color == self.YELLOW: self.m_pixmap.load(":/bitmaps/led_yellow.png") elif self.m_color == self.BIG_RED: self.m_pixmap.load(":/bitmaps/led-big_on.png") else: return else: if self.m_color in (self.BLUE, self.GREEN, self.RED, self.YELLOW): self.m_pixmap.load(":/bitmaps/led_off.png") elif self.m_color == self.BIG_RED: self.m_pixmap.load(":/bitmaps/led-big_off.png") else: return painter.drawPixmap(self.m_pixmap_rect, self.m_pixmap, self.m_pixmap_rect)
def paintEvent(self, event): """QWidget.paintEvent() implementation Draw markers """ painter = QPainter(self) painter.fillRect(event.rect(), self.palette().color(QPalette.Window)) block = self._qpart.firstVisibleBlock() blockBoundingGeometry = self._qpart.blockBoundingGeometry(block).translated(self._qpart.contentOffset()) top = blockBoundingGeometry.top() bottom = top + blockBoundingGeometry.height() for block in qutepart.iterateBlocksFrom(block): height = self._qpart.blockBoundingGeometry(block).height() if top > event.rect().bottom(): break if block.isVisible() and \ bottom >= event.rect().top(): if block.blockNumber() in self._qpart.lintMarks: msgType, msgText = self._qpart.lintMarks[block.blockNumber()] pixMap = self._lintPixmaps[msgType] yPos = top + ((height - pixMap.height()) / 2) # centered painter.drawPixmap(0, yPos, pixMap) if Bookmarks.isBlockMarked(block): yPos = top + ((height - self._bookmarkPixmap.height()) / 2) # centered painter.drawPixmap(0, yPos, self._bookmarkPixmap) top += height
def paintEvent(self, _): s = QToolButton.sizeHint(self) r = 0 p = QPoint() if self.direction == QBoxLayout.TopToBottom: r = 90 p = QPoint(0, -s.height()) elif self.direction == QBoxLayout.BottomToTop: r = -90 p = QPoint(-s.width(), 0) pixmap = QPixmap(s) pixmap.fill(QColor(0, 0, 0, 0)) o = QStyleOptionToolButton() self.initStyleOption(o) o.rect.setSize(s) pixpainter = QPainter() pixpainter.begin(pixmap) self.style().drawComplexControl(QStyle.CC_ToolButton, o, pixpainter, self) pixpainter.end() painter = QPainter(self) painter.rotate(r) painter.drawPixmap(p, pixmap)
def paintEvent(self, event): # the original code tried to be clever about painting an caching. it # only painted the screen if it was dirty. for the redraws when the # dirty flag was not set it relyed on the OS not the clear the cash. # but this does not work (at least on Mac OS X). instead of caching in # the OS cache the screen in a pixmap to have full control over it if self._pixmap == None or self.size() != self._pixmap.size(): self._pixmap = QPixmap(self.size()) self._dirty = True if self._dirty: self._dirty = False pixmap_painter = QPainter(self._pixmap) pixmap_painter.setFont(self.font()) self._paint_screen(pixmap_painter) painter = QPainter(self) painter.drawPixmap(0, 0, self._pixmap) # We don't use the blinky cursor for now # if self._cursor_rect is not None and self._selection is None: # self._paint_cursor(painter) if self._selection: self._paint_selection(painter) self._dirty = True
def paintEvent(self, event): # 回波绘制 绘制到后台缓存 painterToPixmap = QPainter(self.mPixmap) self.mEchoSet.Draw(painterToPixmap) painter = QPainter(self) painter.drawPixmap(0, 0, self.width(), self.height(), self.mPixmap)
def paintEvent(self, event): # 回波绘制 绘制到后台缓存 painterToPixmap = QPainter(self.mPixmap) self.mEchoSet.Draw(painterToPixmap) painter = QPainter(self) painter.drawPixmap(0, 0, self.width(), self.height(), self.mPixmap)
def loadOverlayed(self, name, overlay=None, size=128, overlay_size=16, position=2): if not overlay: return self.load(name, size) position = { self.TopLeft: (0, 0), self.TopRight: (size - overlay_size, 0), self.BottomLeft: (0, size - overlay_size), self.BottomRight: (size - overlay_size, size - overlay_size) }[position] icon = self.load(name, size).scaled(QSize(size, size), Qt.KeepAspectRatio, Qt.SmoothTransformation) overlay = self.load(overlay, overlay_size) overlay = overlay.scaled(QSize(overlay_size, overlay_size), Qt.KeepAspectRatio, Qt.SmoothTransformation) painter = QPainter(icon) painter.drawPixmap(position[0], position[1], overlay) return icon
def paintEvent(self, event): painter = QPainter(self) painter.drawPixmap(0, 0, self.width(), self.height() - 8, self.__pic_bg, 12, 28, 1, 54) painter.drawPixmap(0, self.height() - 8, self.width(), 8, self.__pic_bg, 12, 82, 1, 8)
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setOpacity(self.pixmap_opacity) painter.drawPixmap(0, 0, self.old_pixmap) painter.end()
def paintEvent(self, _): s = QToolButton.sizeHint(self) r = 0 p = QPoint() if self.direction == QBoxLayout.TopToBottom: r = 90 p = QPoint(0, -s.height()) elif self.direction == QBoxLayout.BottomToTop: r = -90 p = QPoint(-s.width(), 0) pixmap = QPixmap(s) pixmap.fill(QColor(0, 0, 0, 0)) o = QStyleOptionToolButton() self.initStyleOption(o) o.rect.setSize(s) pixpainter = QPainter() pixpainter.begin(pixmap) self.style().drawComplexControl(QStyle.CC_ToolButton, o, pixpainter, self) pixpainter.end() painter = QPainter(self) painter.rotate(r) painter.drawPixmap(p, pixmap)
def decorate_welcome_icon(icon, background_color): """Return a `QIcon` with a circle shaped background. """ welcome_icon = QIcon() sizes = [32, 48, 64, 80] background_color = NAMED_COLORS.get(background_color, background_color) background_color = QColor(background_color) grad = radial_gradient(background_color) for size in sizes: icon_pixmap = icon.pixmap(5 * size / 8, 5 * size / 8) icon_size = icon_pixmap.size() icon_rect = QRect(QPoint(0, 0), icon_size) pixmap = QPixmap(size, size) pixmap.fill(QColor(0, 0, 0, 0)) p = QPainter(pixmap) p.setRenderHint(QPainter.Antialiasing, True) p.setBrush(QBrush(grad)) p.setPen(Qt.NoPen) ellipse_rect = QRect(0, 0, size, size) p.drawEllipse(ellipse_rect) icon_rect.moveCenter(ellipse_rect.center()) p.drawPixmap(icon_rect.topLeft(), icon_pixmap) p.end() welcome_icon.addPixmap(pixmap) return welcome_icon
def drawThreshMask(self, worm_img, worm_qimg, row_data, read_center=True): min_mask_area = row_data['area'] / 2 c1, c2 = (row_data['coord_x'], row_data['coord_y']) if read_center else (-1, -1) worm_mask, _ , _ = getWormMask(worm_img, row_data['threshold'], strel_size = self.strel_size, \ roi_center_x = c1, roi_center_y = c2, min_mask_area = min_mask_area) #worm_mask = np.zeros_like(worm_mask) #cv2.drawContours(worm_mask, [worm_cnt.astype(np.int32)], 0, 1, -1) worm_mask = QImage(worm_mask.data, worm_mask.shape[1], worm_mask.shape[0], worm_mask.strides[0], QImage.Format_Indexed8) worm_mask = worm_mask.convertToFormat(QImage.Format_RGB32, Qt.AutoColor) worm_mask = worm_mask.scaled(worm_qimg.width(), worm_qimg.height(), Qt.KeepAspectRatio) worm_mask = QPixmap.fromImage(worm_mask) worm_mask = worm_mask.createMaskFromColor(Qt.black) p = QPainter(worm_qimg) p.setPen(QColor(0, 204, 102)) p.drawPixmap(worm_qimg.rect(), worm_mask, worm_mask.rect()) p.end()
def paintEvent(self, event): painter = QPainter(self) event.accept() if self.isChecked(): if self.fLastColor != self.fColor: if self.fColor == self.OFF: self.fPixmap.load("bitmaps/led_off.png") elif self.fColor == self.BLUE: self.fPixmap.load("bitmaps/led_blue.png") elif self.fColor == self.GREEN: self.fPixmap.load("bitmaps/led_green.png") elif self.fColor == self.RED: self.fPixmap.load("bitmaps/led_red.png") elif self.fColor == self.YELLOW: self.fPixmap.load("bitmaps/led_yellow.png") else: return self.fLastColor = self.fColor elif self.fLastColor != self.OFF: self.fPixmap.load("bitmaps/led_off.png") self.fLastColor = self.OFF painter.drawPixmap(self.fPixmapRect, self.fPixmap, self.fPixmapRect)
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 paintEvent( self, event ): """ Paints the widget based on its values :param event | <QPaintEvent> """ painter = QPainter(self) count = self.maximum() - self.minimum() value = self.value() w = self.pixmapSize().width() h = self.pixmapSize().height() x = 2 y = (self.height() - h) / 2 delta_x = (self.width() - 4 - (w * count - 1)) / (count - 1) full_pixmap = self.fullPixmap().scaled(w, h) empty_pixmap = self.emptyPixmap().scaled(w, h) for i in range(count): if ( i < value ): painter.drawPixmap(x, y, full_pixmap) else: painter.drawPixmap(x, y, empty_pixmap) x += w + delta_x
def paintEvent(self, event): painter = QPainter(self) icon = self.icon_pressed if self.isDown() else self.icon if icon is not None: x = (self.width() - icon.width()) / 2 y = (self.height() - icon.height()) / 2 painter.drawPixmap(x, y, icon) else: width = self.width() height = self.height() padding = width / 5 radius = width - 2 * padding palette = self.palette() # Mid is darker than Dark. Go figure... -Dan bg_color = palette.color( QPalette.Mid) if self.isDown() else palette.color( QPalette.Dark) fg_color = palette.color( QPalette.Window) # or QPalette.Base for white painter.setRenderHint(QPainter.Antialiasing, True) painter.setBrush(bg_color) painter.setPen(bg_color) painter.drawEllipse(padding, padding, radius, radius) padding = padding * 2 painter.setPen(fg_color) painter.drawLine(padding, padding, width - padding, height - padding) painter.drawLine(padding, height - padding, width - padding, padding)
def paintEvent(self, event): painter = QPainter(self) minSize = min(self.rect().width(), self.rect().height()) myRect = QRect(self.rect().x(), self.rect().y(), minSize, minSize) painter.drawPixmap(myRect, self.backgroundPic, self.backgroundPic.rect()) pen = QPen() pen.setCapStyle(Qt.RoundCap) pen.setWidthF(4.0) pen.setColor(Qt.red) pen.setJoinStyle(Qt.RoundJoin) painter.setPen(pen) spacing = 40 contentRect = myRect.adjusted(spacing, spacing, -spacing, -spacing) valueInPercent = (self.m_value - self.m_minimum) / (self.m_maximum - self.m_minimum) math_pi = 3.14159265358979323846 degree = (self.m_startAngle + 90) - valueInPercent * 2.0 * self.m_startAngle degree = degree * math_pi / 180.0 radius = (contentRect.width() - spacing * 0.5) * 0.5 vec = QPoint(radius * math.cos(degree), radius * -math.sin(degree)) painter.drawLine(contentRect.center(), contentRect.center() + vec)
def paintEvent(self, event): # the original code tried to be clever about painting an caching. it # only painted the screen if it was dirty. for the redraws when the # dirty flag was not set it relyed on the OS not the clear the cash. # but this does not work (at least on Mac OS X). instead of caching in # the OS cache the screen in a pixmap to have full control over it if self._pixmap == None or self.size() != self._pixmap.size(): self._pixmap = QPixmap(self.size()) self._dirty = True if self._dirty: self._dirty = False pixmap_painter = QPainter(self._pixmap) pixmap_painter.setFont(self.font()) self._paint_screen(pixmap_painter) painter = QPainter(self) painter.drawPixmap(0, 0, self._pixmap) # We don't use the blinky cursor for now # if self._cursor_rect is not None and self._selection is None: # self._paint_cursor(painter) if self._selection: self._paint_selection(painter) self._dirty = True
def getProtoStatusIcon(name, proto_int=None): """Creates a nice little overlay of the status and the protocol icon. Returns QIcon""" status_icon = getIcon(name) if not proto_int: return status_icon else: ret = _status_icon_cache.get((name, proto_int), None) if ret: return ret proto_name, _ = proto_name_int(proto_int, _PROTO_INT) status_pixmap = status_icon.pixmap(QSize(16,16)) proto_pixmap = getIcon(proto_name).pixmap(QSize(16,16)) combined_pixmap = QImage(28,20, QImage.Format_ARGB32_Premultiplied) painter = QPainter(combined_pixmap) painter.setCompositionMode(painter.CompositionMode_Source) painter.fillRect(combined_pixmap.rect(), Qt.transparent) painter.setCompositionMode(painter.CompositionMode_Source) painter.drawPixmap(QPoint(0,0), status_pixmap) painter.setCompositionMode(painter.CompositionMode_SourceOver) painter.drawPixmap(QPoint(12,4), proto_pixmap) painter.end() #add cache _status_icon_cache[(name, proto_int)] = QIcon(QPixmap.fromImage(combined_pixmap)) return _status_icon_cache[(name, proto_int)]
def paintEvent(self, event): painter = QPainter(self) icon = self.icon_pressed if self.isDown() else self.icon if icon is not None: x = (self.width() - icon.width()) / 2 y = (self.height() - icon.height()) / 2 painter.drawPixmap(x, y, icon) else: width = self.width() height = self.height() padding = width / 5 radius = width - 2*padding palette = self.palette() # Mid is darker than Dark. Go figure... -Dan bg_color = palette.color(QPalette.Mid) if self.isDown() else palette.color(QPalette.Dark) fg_color = palette.color(QPalette.Window) # or QPalette.Base for white painter.setRenderHint(QPainter.Antialiasing, True) painter.setBrush(bg_color) painter.setPen(bg_color) painter.drawEllipse(padding, padding, radius, radius) padding = padding * 2 painter.setPen(fg_color) painter.drawLine(padding, padding, width-padding, height-padding) painter.drawLine(padding, height-padding, width-padding, padding)
def paintEvent(self, event): """ Paints the widget based on its values :param event | <QPaintEvent> """ painter = QPainter(self) count = self.maximum() - self.minimum() value = self.value() w = self.pixmapSize().width() h = self.pixmapSize().height() x = 2 y = (self.height() - h) / 2 delta_x = (self.width() - 4 - (w * count - 1)) / (count - 1) full_pixmap = self.fullPixmap().scaled(w, h) empty_pixmap = self.emptyPixmap().scaled(w, h) for i in range(count): if (i < value): painter.drawPixmap(x, y, full_pixmap) else: painter.drawPixmap(x, y, empty_pixmap) x += w + delta_x
def decorate_welcome_icon(icon, background_color): """Return a `QIcon` with a circle shaped background. """ welcome_icon = QIcon() sizes = [32, 48, 64, 80] background_color = NAMED_COLORS.get(background_color, background_color) background_color = QColor(background_color) grad = radial_gradient(background_color) for size in sizes: icon_pixmap = icon.pixmap(5 * size / 8, 5 * size / 8) icon_size = icon_pixmap.size() icon_rect = QRect(QPoint(0, 0), icon_size) pixmap = QPixmap(size, size) pixmap.fill(QColor(0, 0, 0, 0)) p = QPainter(pixmap) p.setRenderHint(QPainter.Antialiasing, True) p.setBrush(QBrush(grad)) p.setPen(Qt.NoPen) ellipse_rect = QRect(0, 0, size, size) p.drawEllipse(ellipse_rect) icon_rect.moveCenter(ellipse_rect.center()) p.drawPixmap(icon_rect.topLeft(), icon_pixmap) p.end() welcome_icon.addPixmap(pixmap) return welcome_icon
def preparePixmap(self): """ Prepare the pixmap(s) for the transition. This method draws the starting pixmap into the output pixmap. The transition update then draws over the output with the proper portion of the ending pixmap. """ start = self.startPixmap() end = self.endPixmap() size = start.size().expandedTo(end.size()) width = size.width() height = size.height() painter = QPainter(self.outPixmap()) painter.drawPixmap(0, 0, start) direction = self.direction() if direction == self.LeftToRight: start_rect = QRect(0, 0, 0, height) elif direction == self.RightToLeft: start_rect = QRect(width, 0, 0, height) elif direction == self.TopToBottom: start_rect = QRect(0, 0, width, 0) elif direction == self.BottomToTop: start_rect = QRect(0, height, width, 0) else: raise ValueError('Invalid direction: %s' % direction) end_rect = QRect(0, 0, width, height) return start_rect, end_rect
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 paintEvent(self, QPaintEvent): QLabel.paintEvent(self, QPaintEvent) painter = QPainter(self) for i in range(15): for j in range(15): if self.boardArray[i][j] == 1: painter.drawPixmap(i * 32 + 5, j * 32 + 5, self.whiteChess)
def paintEvent(self, event): super(BackgroundFrame, self).paintEvent(event) painter = QPainter(self) if self.backgroundColor: painter.fillRect(self.rect(), QColor(self.backgroundColor)) if self.scaled_pixmap is not None: painter.drawPixmap(self.image_position, self.scaled_pixmap) painter.end()
def paintEvent(self, event): super(BackgroundFrame, self).paintEvent(event) painter = QPainter(self) if self.backgroundColor: painter.fillRect(self.rect(), QColor(self.backgroundColor)) if self.scaled_pixmap is not None: painter.drawPixmap(self.image_position, self.scaled_pixmap) painter.end()
def updatePixmap(self, rect): """ Update the pixmap for the current transition. This method paints the current rect from the internal slide pixmap into the output pixmap. """ painter = QPainter(self.outPixmap()) painter.drawPixmap(QPoint(0, 0), self._slide_pixmap, rect)
def paintEvent(self, event): QWidget.paintEvent(self, event) if self._timeline.state() == QTimeLine.NotRunning: # nothing to do return p = QPainter(self) p.setRenderHint(QPainter.SmoothPixmapTransform, True) p.drawPixmap(QPoint(0, 0), self._prev_pixmap) p.setOpacity(self._blending_factor) p.drawPixmap(QPoint(0, 0), self._next_pixmap)
def paintEvent(self,paintEvent): """设置背景图片,画线""" painter = QPainter(self) #设置背景图片 painter.drawPixmap(self.rect(),QPixmap("images/background.png")) #获取四条线路径 self.updateLinesPath() painter.setPen(QPen(QColor(Qt.lightGray),1)) painter.drawPath(self.linesPath)
def paintEvent(self, paintevent): super(URLLabel, self).paintEvent(paintevent) # Manually draw the downloaded pixmap, scaled to fit the size of the label. if self._original_pixmap: size = self.size() sized_pixmap = self._original_pixmap.scaled(size, Qt.KeepAspectRatio, Qt.SmoothTransformation) painter = QPainter(self) point = self.geometry().topLeft() painter.drawPixmap(point, sized_pixmap)
def updatePixmap(self, rect): """ Update the pixmap for the current transition. This method paints the current rect from the ending pixmap into the proper rect of the output pixmap. """ painter = QPainter(self.outPixmap()) painter.drawPixmap(rect, self.endPixmap(), rect)
def event(self, event): if event.type() == event.Paint: pixmap = self.__pixmap painter = QPainter(self) if not pixmap.isNull(): painter.drawPixmap(0, 0, pixmap) self.drawContents(painter) return True return QSplashScreen.event(self, event)
def event(self, event): if event.type() == event.Paint: pixmap = self.__pixmap painter = QPainter(self) if not pixmap.isNull(): painter.drawPixmap(0, 0, pixmap) self.drawContents(painter) return True return QSplashScreen.event(self, event)
def paintEvent(self, event): QWidget.paintEvent(self, event) painter = QPainter(self) painter.drawText(self.rect(), Qt.AlignLeft | Qt.AlignVCenter, self.weatherText) if not self.pixmap.isNull(): r = self.pixmap.rect() r.moveTop(5) r.moveRight(self.width() - 5) painter.drawPixmap(r, self.pixmap)
def __addEmblem(self, pixmap, emblem): if not emblem is None: painter = QPainter() painter.begin(pixmap) dest = emblem.rect() dest.translate(pixmap.rect().width()- emblem.rect().width(), pixmap.rect().height()- emblem.rect().height()) painter.drawPixmap(dest, emblem, emblem.rect()) painter.end()
def paintEvent(self, event): QWidget.paintEvent(self, event) painter = QPainter(self) painter.drawText(self.rect(), Qt.AlignLeft | Qt.AlignVCenter, self.weatherText) if not self.pixmap.isNull(): r = self.pixmap.rect() r.moveTop(5) r.moveRight(self.width() - 5) painter.drawPixmap(r, self.pixmap)
def x_bitmap_opaque ( self, bitmap ): """ Returns a version of the specified bitmap with no transparency. """ dx = bitmap.width() dy = bitmap.height() opaque_bitmap = QPixmap( dx, dy ) opaque_bitmap.fill( WindowColor ) q = QPainter( opaque_bitmap ) q.drawPixmap( 0, 0, bitmap ) return opaque_bitmap
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 _decorateIcon(originalIcon, iconPath): """ Decorates the icon with the icon identified by C{iconPath}. """ originalPm = originalIcon.pixmap(16) painter = QPainter(originalPm) pm = QPixmap(iconPath) targetRect = QRectF(0.0, 8.0, 8.0, 8.0) sourceRect = QRectF(0.0, 0.0, 16, 16) painter.drawPixmap(targetRect, pm, sourceRect) painter.end() return QIcon(originalPm)
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 preparePixmap(self): """ Prepare the pixmap(s) for the transition. This method draws the starting pixmap into the output pixmap. The transition updates then draw the two pixmaps with an appropriate alpha blending value. """ painter = QPainter(self.outPixmap()) painter.drawPixmap(QPoint(0, 0), self.startPixmap()) return 0.0, 1.0
def preparePixmap(self): """ Prepare the pixmap(s) for the transition. This method draws the starting pixmap into the output pixmap. The transition updates then draw the relevant pixmaps into the output using an appropriate alpha. """ painter = QPainter(self.outPixmap()) painter.drawPixmap(QPoint(0, 0), self.startPixmap()) return -1.0, 1.0
def print_photo(self): print_dialog = QPrintDialog(self._printer,self) if print_dialog.exec_() == QDialog.Accepted: painter = QPainter(self._printer) rect = painter.viewport() size = self._lbl_photo.pixmap().size() size.scale(rect.size(), Qt.KeepAspectRatio) painter.setViewport(rect.x(), rect.y(), size.width(), size.height()) painter.setWindow(self._lbl_photo.pixmap().rect()) painter.drawPixmap(0, 0, self._lbl_photo.pixmap())
def _decorateIcon(originalIcon, iconPath): """ Decorates the icon with the icon identified by C{iconPath}. """ originalPm = originalIcon.pixmap(16) painter = QPainter(originalPm) pm = QPixmap(iconPath) targetRect = QRectF(0.0, 8.0, 8.0, 8.0) sourceRect = QRectF(0.0, 0.0, 16, 16) painter.drawPixmap(targetRect, pm, sourceRect) painter.end() return QIcon(originalPm)
def paintEvent(self, ev): image = self.viewer.image() painter = QPainter(self) if self.size() == image.size(): painter.drawImage(ev.rect(), image, ev.rect()) else: s = image.size() s.scale(self.size(), Qt.KeepAspectRatio) r = QRect() r.setSize(s) r.moveCenter(self.rect().center()) painter.drawPixmap(r, self.viewer.pixmap(s))
def data(self, index, role): if not index.isValid(): return None item = index.internalPointer() ret = None if role == Qt.DisplayRole: if index.column() == 0: ret = item.exp elif index.column() == 1: ret = item.type elif index.column() == 2: ret = item.value elif role == Qt.EditRole: if index.column() == 2: ret = item.value elif role == Qt.DecorationRole: if index.column() == 0: if item.access in ['private', 'protected']: iconprefix = item.access + "_" else: iconprefix = "" icon = None if not item.inScope: return QPixmap(":/icons/images/outofscope.png") elif not isinstance(item, StdVariable): icon = QPixmap(":/icons/images/" + iconprefix + "struct.png") else: # leave item icon = QPixmap(":/icons/images/" + iconprefix + "var.png") # overlay for arguments if icon and item.arg: ol = QPixmap(":/icons/images/overlay_arg.png") p = QPainter(icon) p.drawPixmap(ol.rect(), ol) elif icon and item.exp == "Return value": ol = QPixmap(":/icons/images/overlay_ret.png") p = QPainter(icon) p.drawPixmap(ol.rect(), ol) return icon elif role == Qt.BackgroundRole: if not item.inScope: ret = QBrush(Qt.gray) elif index.column() == 2: if item.marked and item.inScope: ret = QBrush(Qt.yellow) return ret
def paintEvent(self, ev): image = self.viewer.image() painter = QPainter(self) if self.size() == image.size(): painter.drawImage(ev.rect(), image, ev.rect()) else: s = image.size() s.scale(self.size(), Qt.KeepAspectRatio) r = QRect() r.setSize(s) r.moveCenter(self.rect().center()) painter.drawPixmap(r, self.viewer.pixmap(s))
def paintEvent(self, event): """ Paint the interpolated pixmap image. """ p = QPainter(self) p.setClipRect(event.rect()) factor = self.blendingFactor_ ** 2 if self.pixmap1 and 1. - factor: p.setOpacity(1. - factor) p.drawPixmap(QPoint(0, 0), self.pixmap1) if self.pixmap2 and factor: p.setOpacity(factor) p.drawPixmap(QPoint(0, 0), self.pixmap2)
def _load_icon(filename, backgroundColor, width, height): foreground = QPixmap() foreground.load(filename) pixmap = QPixmap(foreground.size()) pixmap.fill(backgroundColor) painter = QPainter() painter.begin(pixmap) painter.drawPixmap(QPointF(0, 0), foreground) painter.end() pixmap = pixmap.scaled(QSize(width, height), Qt.KeepAspectRatio, Qt.SmoothTransformation) return pixmap
def paintEvent(self, event): if self.__pixmap.isNull(): return sourcerect = QRect(QPoint(0, 0), self.__pixmap.size()) pixsize = QSizeF(self.__pixmap.size()) rect = self.contentsRect() pixsize.scale(QSizeF(rect.size()), Qt.KeepAspectRatio) targetrect = QRectF(QPointF(0, 0), pixsize) targetrect.moveCenter(QPointF(rect.center())) painter = QPainter(self) painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.drawPixmap(targetrect, self.__pixmap, QRectF(sourcerect)) painter.end()