def paintEvent(self, event): """ Render the UI. """ if self._mode == self.MODE_OFF: return painter = QtGui.QPainter() painter.begin(self) try: # set up semi transparent backdrop painter.setRenderHint(QtGui.QPainter.Antialiasing) overlay_color = QtGui.QColor(30, 30, 30, 100) painter.setBrush( QtGui.QBrush(overlay_color)) painter.setPen(QtGui.QPen(overlay_color)) painter.drawRect(0, 0, painter.device().width(), painter.device().height()) # show the spinner painter.translate((painter.device().width() / 2) - 10, (painter.device().height() / 2) - 10) pen = QtGui.QPen(QtGui.QColor(self._bundle.style_constants["SG_HIGHLIGHT_COLOR"])) pen.setWidth(1) painter.setPen(pen) r = QtCore.QRectF(0.0, 0.0, 20.0, 20.0) start_angle = (0 + self._spin_angle) * 4 * 16 span_angle = 340 * 16 painter.drawArc(r, start_angle, span_angle) finally: painter.end()
def paintEvent(self, event): """ Paint the widget :param event: The QPaintEvent event """ # call the base paint event: QtGui.QWidget.paintEvent(self, event) painter = QtGui.QPainter() painter.begin(self) try: painter.setRenderHint(QtGui.QPainter.Antialiasing) # use the foreground colour to paint with: fg_col = self.palette().color(self.foregroundRole()) pen = QtGui.QPen(fg_col) pen.setWidth(self.line_width) painter.setPen(pen) border = self.border + int(math.ceil(self.line_width / 2.0)) r = QtCore.QRect(0, 0, self.width(), self.height()) r.adjust(border, border, -border, -border) # draw the arc: painter.drawArc(r, -self._start_angle * 16, self.arc_length * 16) r = None finally: painter.end() painter = None
def paintEvent(self, paint_event): """ Paint Event override """ # paint multiple values indicator if self._multiple_values == True: p = QtGui.QPainter(self) p.drawPixmap( 0, 0, self.width(), self.height(), self._no_thumb_pixmap, 0, 0, self._no_thumb_pixmap.width(), self._no_thumb_pixmap.height(), ) p.fillRect(0, 0, self.width(), self.height(), QtGui.QColor(42, 42, 42, 237)) p.setFont(QtGui.QFont("Arial", 15, QtGui.QFont.Bold)) pen = QtGui.QPen(QtGui.QColor("#18A7E3")) p.setPen(pen) p.drawText(self.rect(), QtCore.Qt.AlignCenter, "Multiple Values") else: # paint thumbnail QtGui.QLabel.paintEvent(self, paint_event)
def create_overlayed_user_publish_thumbnail(publish_pixmap, user_pixmap): """ Creates a sqaure 75x75 thumbnail with an optional overlayed pixmap. """ # create a 100x100 base image base_image = QtGui.QPixmap(75, 75) base_image.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(base_image) painter.setRenderHint(QtGui.QPainter.Antialiasing) # scale down the thumb if not publish_pixmap.isNull(): thumb_scaled = publish_pixmap.scaled( 75, 75, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation) # now composite the thumbnail on top of the base image # bottom align it to make it look nice thumb_img = thumb_scaled.toImage() brush = QtGui.QBrush(thumb_img) painter.save() painter.setBrush(brush) painter.setPen(QtGui.QPen(QtCore.Qt.NoPen)) painter.drawRect(0, 0, 75, 75) painter.restore() if user_pixmap and not user_pixmap.isNull(): # overlay the user picture on top of the thumbnail user_scaled = user_pixmap.scaled( 30, 30, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation) user_img = user_scaled.toImage() user_brush = QtGui.QBrush(user_img) painter.save() painter.translate(42, 42) painter.setBrush(user_brush) painter.setPen(QtGui.QPen(QtCore.Qt.NoPen)) painter.drawRect(0, 0, 30, 30) painter.restore() painter.end() return base_image
def paintEvent(self, event): QtGui.QPushButton.paintEvent(self, event) if self.version: painter = QtGui.QPainter(self) painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255, 255))) painter.drawText(self.rect().adjusted(3, 0, 0, 0), QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, str(self.version))
def drawLineTo(self, endPoint): painter = QtGui.QPainter(self.image) painter.setPen( QtGui.QPen(self.myPenColor, self.myPenWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) painter.drawLine(self.lastPoint, endPoint) self.modified = True rad = self.myPenWidth / 2 + 2 self.update( QtCore.QRect(self.lastPoint, endPoint).normalized().adjusted( -rad, -rad, +rad, +rad)) self.lastPoint = QtCore.QPoint(endPoint)
def create_rectangular_512x400_thumbnail(image): """ Given a QImage shotgun thumbnail, create a rectangular icon with the thumbnail composited onto a centered otherwise empty canvas. This will return a 512x400 pixmap object. :param image: QImage source image :returns: QPixmap rectangular thumbnail on a 512x400 rect backdrop """ CANVAS_WIDTH = 512 CANVAS_HEIGHT = 400 CORNER_RADIUS = 10 # get the 512 base image base_image = QtGui.QPixmap(CANVAS_WIDTH, CANVAS_HEIGHT) base_image.fill(QtCore.Qt.transparent) # now attempt to load the image # pixmap will be a null pixmap if load fails thumb = QtGui.QPixmap.fromImage(image) if not thumb.isNull(): # scale it down to fit inside a frame of maximum 512x512 thumb_scaled = thumb.scaled( CANVAS_WIDTH, CANVAS_HEIGHT, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation, ) # now composite the thumbnail on top of the base image # bottom align it to make it look nice thumb_img = thumb_scaled.toImage() brush = QtGui.QBrush(thumb_img) painter = QtGui.QPainter(base_image) painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.setBrush(brush) painter.setPen(QtGui.QPen()) painter.drawRoundedRect( 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, CORNER_RADIUS, CORNER_RADIUS ) painter.end() return base_image
def __init__(self, parent=None): """ Initialize the widget. """ super(ViewItemDelegateDemo, self).__init__(parent) self._bg_task_manager = task_manager.BackgroundTaskManager(self, True) shotgun_globals.register_bg_task_manager(self._bg_task_manager) # Create two separate models to demonstrate how each type can be used with the ViewItemDelegate # # The BasicListItemModel is a QAbstractItemModel (e.g. does not use QStandardItems) self._basic_model = BasicListItemModel(self) # The BasicShotgunModel is a subclass of the ShotgunModel, whichh is a QStandardItemModel (e.g. # uses QStandardItem objects) self._shotgun_model = BasicShotgunModel.create_task_model( self._bg_task_manager, self ) # Create and a single view to display the both the BasicListModel and BasicShotgunModel data self._view = QtGui.QListView(self) # Enable mouse tracking for the delegate to receive mouse events self._view.setMouseTracking(True) # Put the onus on the delegate to determin view item sizes self._view.setUniformItemSizes(False) # Create four delegates to render the view using the BasicListModel and BasicShotgunModel, and # in both List and Thumbnail view modes self._list_view_delegate = self._create_delegate(self._view, BasicListItemModel) self._thumbnail_view_delegate = self._create_delegate( self._view, BasicListItemModel, thumbnail_mode=True ) self._shotgun_list_view_delegate = self._create_delegate( self._view, BasicShotgunModel ) self._shotgun_thumbnail_view_delegate = self._create_delegate( self._view, BasicShotgunModel, thumbnail_mode=True ) # Add border specifically to shotgun data thumbnail view background_pen = QtGui.QPen(QtCore.Qt.black) background_pen.setWidthF(0.5) self._shotgun_thumbnail_view_delegate.background_pen = background_pen # Build and layout the UI. self._populate_ui()
def __create_rounded_rect_thumbnail(image, canvas_width, canvas_height, radius): """ Given a qimage shotgun thumbnail, create a publish icon with the thumbnail composited onto a centered otherwise empty canvas. The thumbnail will be taking up all the space in the image. :param image: QImage to load thumbnail from :param canvas_width: Width of image to generate, in pixels :param canvas_height: Heiht of image to generate, in pixels :param radius: Corner radius of image to generate, in pixels :returns: QPixmap object """ # get the base image base_image = QtGui.QPixmap(canvas_width, canvas_height) base_image.fill(QtCore.Qt.transparent) # now attempt to load the image # pixmap will be a null pixmap if load fails thumb = QtGui.QPixmap.fromImage(image) if not thumb.isNull(): # scale it down to fit inside a frame thumb_scaled = thumb.scaled( canvas_width, canvas_height, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation, ) # now composite the thumbnail on top of the base image # bottom align it to make it look nice thumb_img = thumb_scaled.toImage() brush = QtGui.QBrush(thumb_img) painter = QtGui.QPainter(base_image) painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.setBrush(brush) painter.setPen(QtGui.QPen()) painter.drawRoundedRect(0, 0, canvas_width, canvas_height, radius, radius) painter.end() return base_image
def __format_thumbnail(self, pixmap_obj): """ Given a screengrab, create a thumbnail object, scaled to 96x75 px and with a subtle rounded frame. :param pixmap_obj: input screenshot :returns: 96x75px pixmap """ CANVAS_WIDTH = 96 CANVAS_HEIGHT = 75 CORNER_RADIUS = 6 # get the 512 base image base_image = QtGui.QPixmap(CANVAS_WIDTH, CANVAS_HEIGHT) base_image.fill(QtCore.Qt.transparent) # scale it down to fit inside a frame of maximum 512x512 thumb_scaled = pixmap_obj.scaled(CANVAS_WIDTH, CANVAS_HEIGHT, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation) # now composite the thumbnail on top of the base image # bottom align it to make it look nice thumb_img = thumb_scaled.toImage() brush = QtGui.QBrush(thumb_img) painter = QtGui.QPainter(base_image) painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.setBrush(brush) pen = QtGui.QPen(QtGui.QColor("#2C93E2")) pen.setWidth(3) painter.setPen(pen) # note how we have to compensate for the corner radius painter.drawRoundedRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, CORNER_RADIUS, CORNER_RADIUS) painter.end() return base_image
def paintEvent(self, paint_event): """ Paints the line plain text editor and adds a placeholder on bottom right corner when multiple values are detected. """ # If the box does not have focus, draw <multiple values> placeholder when self._show_placeholder is true, even if the widget has text if not self.hasFocus() and self._show_placeholder == True: p = QtGui.QPainter(self.viewport()) # right placeholder note in blue col = QtGui.QColor(24,167,227) # blue p.setPen(QtGui.QPen(col)) p.setBrush(QtGui.QBrush(col)) p.drawText(self.rect(),QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft, self._placeholder_text) else: QtGui.QPlainTextEdit.paintEvent(self, paint_event)
def paintEvent(self, event): """ Render the UI. """ if self._mode == self.MODE_OFF: return painter = QtGui.QPainter() painter.begin(self) try: # set up semi transparent backdrop painter.setRenderHint(QtGui.QPainter.Antialiasing) overlay_color = QtGui.QColor(30, 30, 30, 160) painter.setBrush( QtGui.QBrush(overlay_color)) painter.setPen(QtGui.QPen(overlay_color)) painter.drawRect(0, 0, painter.device().width(), painter.device().height()) finally: painter.end()
def paintEvent(self, event): """ Paint event """ # Convert click and current mouse positions to local space. mouse_pos = self.mapFromGlobal(QtGui.QCursor.pos()) click_pos = None if self._click_pos is not None: click_pos = self.mapFromGlobal(self._click_pos) painter = QtGui.QPainter(self) # Draw background. Aside from aesthetics, this makes the full # tool region accept mouse events. painter.setBrush(QtGui.QColor(0, 0, 0, self._opacity)) painter.setPen(QtCore.Qt.NoPen) painter.drawRect(event.rect()) # Clear the capture area if click_pos is not None: capture_rect = QtCore.QRect(click_pos, mouse_pos) painter.setCompositionMode(QtGui.QPainter.CompositionMode_Clear) painter.drawRect(capture_rect) painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver) pen = QtGui.QPen(QtGui.QColor(255, 255, 255, 64), 1, QtCore.Qt.DotLine) painter.setPen(pen) # Draw cropping markers at click position if click_pos is not None: painter.drawLine( event.rect().left(), click_pos.y(), event.rect().right(), click_pos.y() ) painter.drawLine( click_pos.x(), event.rect().top(), click_pos.x(), event.rect().bottom() ) # Draw cropping markers at current mouse position painter.drawLine( event.rect().left(), mouse_pos.y(), event.rect().right(), mouse_pos.y() ) painter.drawLine( mouse_pos.x(), event.rect().top(), mouse_pos.x(), event.rect().bottom() )
def paintEvent(self, paint_event): """ Paints the line plain text editor and adds a placeholder on bottom right corner when multiple values are detected. """ # If the box does not have focus, draw <multiple values> placeholder when self._show_placeholder is true, even if the widget has text if not self.hasFocus() and self._show_multiple_values is True: p = QtGui.QPainter(self.viewport()) # right placeholder note in blue col = QtGui.QColor(self._highlight) # blue p.setPen(QtGui.QPen(col)) p.setBrush(QtGui.QBrush(col)) p.drawText( self.rect(), QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft, self._multiple_values_text, ) else: super(PublishDescriptionEditBase, self).paintEvent(paint_event)
def __init__(self, view): self.tray_view = view shotgun_view.WidgetDelegate.__init__(self, view) self.__selection_model = view.selectionModel() self._pen = QtGui.QPen(QtCore.Qt.white, 1, QtCore.Qt.SolidLine) self._ORIGINAL_THUMBNAIL = QtCore.Qt.UserRole + 1702 self._FILTER_THUMBNAIL = QtCore.Qt.UserRole + 1703 self._PINNED_THUMBNAIL = QtCore.Qt.UserRole + 1704 # pinned icon try: f = os.path.join(os.path.dirname(os.path.abspath(__file__)), "review_app_pinned.png") self.pin_pixmap = QtGui.QPixmap(f) f2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ae.jpeg") self.missing_pixmap = QtGui.QPixmap(f2) except Exception as e: print "ERROR: cant load pin %r" % e
def paintEvent(self, event): """ Override the Qt method. Highlight the background color on mouse hover. """ super(ChoicesFilterItemWidget, self).paintEvent(event) option = QtGui.QStyleOption() option.initFrom(self) painter = QtGui.QPainter() painter.begin(self) try: if option.state & QtGui.QStyle.State_MouseOver: painter.setRenderHint(QtGui.QPainter.Antialiasing) hover_color = option.palette.highlight().color() painter.setBrush(QtGui.QBrush(hover_color)) painter.setPen(QtGui.QPen(hover_color)) painter.drawRect( 0, 0, painter.device().width(), painter.device().height() ) finally: painter.end()