示例#1
0
    def sceneEventFilter(self, obj, event):
        if (event.type() == QtCore.QEvent.GraphicsSceneMousePress
                and event.button() == QtCore.Qt.LeftButton):
            return True

        elif (event.type() == QtCore.QEvent.GraphicsSceneMouseRelease
              and event.button() == QtCore.Qt.LeftButton):
            pen = QtGui.QPen()
            pen.setColor(QtCore.Qt.red)

            brush = QtGui.QBrush()
            brush.setColor(QtCore.Qt.red)
            brush.setStyle(QtCore.Qt.SolidPattern)

            RADIUS = 3
            point = event.scenePos()
            item = GraphicsPointItem(point.x(), point.y(), RADIUS)
            item.setPen(pen)
            item.setBrush(brush)
            item.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, True)
            item.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True)
            obj.addItem(item)
            return True

        return False
示例#2
0
def makeBrush(**option):
    brush = QtGui.QBrush()
    brush.setStyle(option.get('style', Qt.SolidPattern))
    color = QColor(option.get('color', '#ffffff'))
    color.setAlphaF(option.get('alpha', 1))
    brush.setColor(color)
    return brush
示例#3
0
	def arrow(self, sx, sy, ex, ey, body_length=0.8, body_width=.5,
		head_width=30, color=None, fill=False, penwidth=None, add=True):

		"""Mimicks canvas api. See openexp._canvas.canvas."""

		from openexp._canvas.canvas import canvas
		shape = canvas.arrow_shape(self._x(sx), self._y(sy), self._x(ex),
			self._y(ey), body_length=self._p(body_length),
			body_width=self._p(body_width),
			head_width=self._w(head_width))
		color = self._color(color)
		if fill:
			pen = self._pen(color, 1)
			brush = self._brush(color)
		else:
			pen = self._pen(color, penwidth)
			brush = QtGui.QBrush()
		polygon = QtGui.QPolygonF()
		for point in shape:
			polygon <<  QtCore.QPointF(point[0],point[1])
		i = QtWidgets.QGraphicsPolygonItem(polygon)
		i.setPen(pen)
		i.setBrush(brush)
		if add:
			self.addItem(i)
		return i
示例#4
0
 def paintEvent(self, e):
     painter = QtGui.QPainter(self)
     brush = QtGui.QBrush()
     brush.setColor(QtGui.QColor(self.color))
     brush.setStyle(Qt.SolidPattern)
     painter.setBrush(brush)
     painter.drawEllipse(0, 0, self.size, self.size)
示例#5
0
    def __init__(self, *args, **kwargs):
        super(FramelessWindow, self).__init__(*args, **kwargs)
        palette1 = QtGui.QPalette()
        pix = QtGui.QPixmap('images/1.jpg')

        palette1.setBrush(self.backgroundRole(), QtGui.QBrush(pix))  # 设置背景图片
        self.setPalette(palette1)
        self.setAutoFillBackground(True)
        self.setGeometry(300, 300, 250, 150)
        self._pressed = False
        self.Direction = None
        # 无边框
        self.setWindowFlags(Qt.FramelessWindowHint)  # 隐藏边框
        # 鼠标跟踪
        self.setMouseTracking(True)
        # 布局
        layout = QVBoxLayout(self, spacing=0)
        layout.setContentsMargins(0, 0, 0, 0)
        # 标题栏
        self.titleBar = TitleBar(self)
        layout.addWidget(self.titleBar)
        # 信号槽
        self.titleBar.windowMinimumed.connect(self.showMinimized)
        self.titleBar.windowMaximumed.connect(self.showMaximized)
        self.titleBar.windowNormaled.connect(self.showNormal)
        self.titleBar.windowClosed.connect(self.close)
        self.titleBar.windowMoved.connect(self.move)
        self.windowTitleChanged.connect(self.titleBar.setTitle)
        self.windowIconChanged.connect(self.titleBar.setIcon)
示例#6
0
def DrawNumerical(painter, x, y, service_key, rating_state, rating):

    (shape, stars) = GetStars(service_key, rating_state, rating)

    x_delta = 0
    x_step = 12

    for (num_stars, pen_colour, brush_colour) in stars:

        painter.setPen(QG.QPen(pen_colour))
        painter.setBrush(QG.QBrush(brush_colour))

        for i in range(num_stars):

            if shape == CIRCLE:

                painter.drawEllipse(QC.QPointF(x + 7 + x_delta, y + 7), 6, 6)

            elif shape == SQUARE:

                painter.drawRect(x + 2 + x_delta, y + 2, 12, 12)

            elif shape == STAR:

                offset = QC.QPoint(x + 1 + x_delta, y + 1)

                painter.translate(offset)

                painter.drawPolygon(QG.QPolygonF(STAR_COORDS))

                painter.translate(-offset)

            x_delta += x_step
示例#7
0
def DrawLike(painter, x, y, service_key, rating_state):

    shape = GetShape(service_key)

    (pen_colour, brush_colour) = GetPenAndBrushColours(service_key,
                                                       rating_state)

    painter.setPen(QG.QPen(pen_colour))
    painter.setBrush(QG.QBrush(brush_colour))

    if shape == CIRCLE:

        painter.drawEllipse(QC.QPointF(x + 7, y + 7), 6, 6)

    elif shape == SQUARE:

        painter.drawRect(x + 2, y + 2, 12, 12)

    elif shape == STAR:

        offset = QC.QPoint(x + 1, y + 1)

        painter.translate(offset)

        painter.drawPolygon(QG.QPolygonF(STAR_COORDS))

        painter.translate(-offset)
示例#8
0
    def data(self, index, role=QtCore.Qt.DisplayRole):
        if not index.isValid() or not (0 <= index.row() < len(self._builders)):
            return None

        row = index.row()
        column = index.column()
        builder = self._builders[row]

        if role == QtCore.Qt.DisplayRole:
            if column == 0:
                if not builder.materials:
                    return "none"
                else:
                    return ", ".join(
                        map(operator.attrgetter("name"), builder.materials)
                    )
            elif column == 1:
                if len(builder.thicknesses_m) > 0:
                    values = np.array(sorted(builder.thicknesses_m)) * 1e9
                    locale = QtCore.QLocale.system()
                    precision = tolerance_to_decimals(Layer.THICKNESS_TOLERANCE_m * 1e9)
                    return ", ".join(locale.toString(v, "f", precision) for v in values)

        elif role == QtCore.Qt.TextAlignmentRole:
            return QtCore.Qt.AlignCenter

        elif role == QtCore.Qt.UserRole:
            return builder

        elif role == QtCore.Qt.BackgroundRole:
            if len(builder) == 0:
                brush = QtGui.QBrush()
                brush.setColor(QtGui.QColor(INVALID_COLOR))
                brush.setStyle(QtCore.Qt.SolidPattern)
                return brush
示例#9
0
    def updateMarker(self, marker):
        if marker.type.name != "drift_rect":
            return
        if marker.id not in self.overlays:
            overlay = QtWidgets.QGraphicsPolygonItem(self.image)
            overlay.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 255, 128)))
            overlay.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0)))
            self.overlays[marker.id] = overlay
        else:
            overlay = self.overlays[marker.id]
        border_x, border_y = self.getOption("borderSize")
        poly = []
        poly.append(QtCore.QPoint(marker.x - border_x, marker.y - border_y))
        poly.append(
            QtCore.QPoint(marker.x + marker.width + border_x,
                          marker.y - border_y))
        poly.append(
            QtCore.QPoint(marker.x + marker.width + border_x,
                          marker.y + marker.height + border_y))
        poly.append(
            QtCore.QPoint(marker.x - border_x,
                          marker.y + marker.height + border_y))
        poly.append(QtCore.QPoint(marker.x - border_x, marker.y - border_y))

        poly.append(QtCore.QPoint(marker.x, marker.y))
        poly.append(QtCore.QPoint(marker.x + marker.width, marker.y))
        poly.append(
            QtCore.QPoint(marker.x + marker.width, marker.y + marker.height))
        poly.append(QtCore.QPoint(marker.x, marker.y + marker.height))
        poly.append(QtCore.QPoint(marker.x, marker.y))

        overlay.setPolygon(QtGui.QPolygonF(poly))
示例#10
0
    def ellipse(self,
                x,
                y,
                w,
                h,
                fill=False,
                color=None,
                penwidth=None,
                add=True):
        """Mimicks canvas api. See openexp._canvas.canvas."""

        color = self._color(color)
        if fill:
            pen = self._pen(color, 1)
            brush = self._brush(color)
        else:
            pen = self._pen(color, penwidth)
            brush = QtGui.QBrush()
        i = QtWidgets.QGraphicsEllipseItem(self._x(x), self._y(y), self._w(w),
                                           self._h(h))
        i.setPen(pen)
        i.setBrush(brush)
        if add:
            self.addItem(i)
        return i
示例#11
0
    def __init__(self, parent=None):
        super(ImageView, self).__init__(parent)

        scene = QtWidgets.QGraphicsScene(self)
        self.graphics_pixmap = QtWidgets.QGraphicsPixmapItem()
        scene.addItem(self.graphics_pixmap)
        self.setScene(scene)

        self.zoom_factor = 1.125
        self.rubberband = None
        self.panning = False
        self.first_show_occured = False
        self.last_scene_roi = None
        self.start_drag = QtCore.QPoint()
        self.checkerboard = None

        CHECK_MEDIUM = 8
        CHECK_GRAY = 0x80
        CHECK_LIGHT = 0xcc
        check_pattern = QtGui.QImage(CHECK_MEDIUM * 2, CHECK_MEDIUM * 2,
                                     QtGui.QImage.Format_RGB888)
        color_gray = QtGui.QColor(CHECK_GRAY, CHECK_GRAY, CHECK_GRAY)
        color_light = QtGui.QColor(CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT)
        painter = QtGui.QPainter(check_pattern)
        painter.fillRect(0, 0, CHECK_MEDIUM, CHECK_MEDIUM, color_gray)
        painter.fillRect(CHECK_MEDIUM, CHECK_MEDIUM, CHECK_MEDIUM,
                         CHECK_MEDIUM, color_gray)
        painter.fillRect(0, CHECK_MEDIUM, CHECK_MEDIUM, CHECK_MEDIUM,
                         color_light)
        painter.fillRect(CHECK_MEDIUM, 0, CHECK_MEDIUM, CHECK_MEDIUM,
                         color_light)
        self.check_pattern = check_pattern
        self.check_brush = QtGui.QBrush(check_pattern)
示例#12
0
 def setAnning(self, isAnning=True):
     if isAnning:
         self.setAcceptHoverEvents(False)
         self.last_focse = self.polygon_hovering
         self.polygon_hovering = False
         self.anning = True
         self.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
         self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, False)
         # self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, False)
         self.setFlag(QtWidgets.QGraphicsItem.ItemSendsGeometryChanges,
                      False)
         self.setFlag(QtWidgets.QGraphicsItem.ItemIsFocusable, False)
         self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
     else:
         self.setAcceptHoverEvents(True)
         self.anning = False
         if self.last_focse:
             self.polygon_hovering = True
             self.setBrush(self.insideColor)
         else:
             self.setBrush(self.halfInsideColor)
         self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, True)
         # self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True)
         self.setFlag(QtWidgets.QGraphicsItem.ItemSendsGeometryChanges,
                      True)
         self.setFlag(QtWidgets.QGraphicsItem.ItemIsFocusable, True)
         self.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
示例#13
0
    def __init__(self, parent_hud, window, image_display, config):
        QtGui.QGraphicsRectItem.__init__(self, parent_hud)
        self.config = config

        self.window = window
        self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

        self.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 250)))
        self.setZValue(30)

        self.setRect(QtGui.QRectF(0, 0, 110, 110))
        BoxGrabber(self)
        self.dragged = False

        self.hidden = False
        if self.config.hide_interfaces:
            self.setVisible(False)
            self.hidden = True

        self.qimages = []
        self.pixmaps = []
        self.shapes = []
        for i in xrange(600):
            self.pixmaps.append(QtGui.QGraphicsPixmapItem(self))
            self.qimages.append(QtGui.QImage())
            self.shapes.append((0, 0))

        self.offset = [0, 0]

        self.t = checkUpdateThread(self)
        self.t.signal.sig.connect(self.updatePixmap)
        self.started = False
    def data(self, index, role):
        """

        :param index:
        :param role:
        :return:
        """
        """
        Different roles:
        The general purpose roles (and the associated types) are:

        Constant	Value	Description
        Qt::DisplayRole	0	The key data to be rendered in the form of text. (QString)
        Qt::DecorationRole	1	The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap)
        Qt::EditRole	2	The data in a form suitable for editing in an editor. (QString)
        Qt::ToolTipRole	3	The data displayed in the item's tooltip. (QString)
        Qt::StatusTipRole	4	The data displayed in the status bar. (QString)
        Qt::WhatsThisRole	5	The data displayed for the item in "What's This?" mode. (QString)
        Qt::SizeHintRole	13	The size hint for the item that will be supplied to views. (QSize)
        Roles describing appearance and meta data (with associated types):
        
        Constant	Value	Description
        Qt::FontRole	6	The font used for items rendered with the default delegate. (QFont)
        Qt::TextAlignmentRole	7	The alignment of the text for items rendered with the default delegate. (Qt::AlignmentFlag)
        Qt::BackgroundRole	8	The background brush used for items rendered with the default delegate. (QBrush)
        Qt::BackgroundColorRole	8	This role is obsolete. Use BackgroundRole instead.
        Qt::ForegroundRole	9	The foreground brush (text color, typically) used for items rendered with the default delegate. (QBrush)
        Qt::TextColorRole	9	This role is obsolete. Use ForegroundRole instead.
        Qt::CheckStateRole	10	This role is used to obtain the checked state of an item. (Qt::CheckState)
        Qt::InitialSortOrderRole	14	This role is used to obtain the initial sort order of a header view section. (Qt::SortOrder). This role was introduced in Qt 4.8.
        Accessibility roles (with associated types):
        
        Constant	Value	Description
        Qt::AccessibleTextRole	11	The text to be used by accessibility extensions and plugins, such as screen readers. (QString)
        Qt::AccessibleDescriptionRole	12	A description of the item for accessibility purposes. (QString)
        User roles:
        
        Constant	Value	Description
        Qt::UserRole	32	The first role that can be used for application-specific purposes.
        """
        if not index.isValid():
            return None
        # print(f"role {role}")
        # print(f"Qt.UserRole {Qt.UserRole}")
        if role == Qt.DecorationRole:
            item = index.internalPointer()
            return item.data(index.column())

        item = index.internalPointer()

        if (role == Qt.ForegroundRole) and (not item.data_valid):
            color = QtGui.QColor()
            color.setRgb(54, 54, 54)
            return QtGui.QBrush(color)
        if role != Qt.DisplayRole:
            return None

        # print(f"role {role} {Qt.DecorationRole}")

        return item.data(index.column())
示例#15
0
    def __init__(self, x, y, fill_color):
        QtWidgets.QGraphicsPolygonItem.__init__(self)
        self.setPen(mask_pen)
        self.setBrush(QtGui.QBrush(fill_color))

        self.vertices = []
        self.vertices.append(QtCore.QPointF(x, y))
示例#16
0
 def setBlackPen(self, qp):
     color = QtGui.QColor('#000000')
     color.setAlphaF(.5)
     pen = QtGui.QPen(color, 0, QtCore.Qt.SolidLine)
     brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
     qp.setPen(pen)
     qp.setBrush(brush)
     return qp
示例#17
0
    def __init__(self, x, y, width, height, fill_color):
        QtWidgets.QGraphicsRectItem.__init__(self, x, y + height, width,
                                             height)
        self.setPen(mask_pen)
        self.setBrush(QtGui.QBrush(fill_color))

        self.initial_x = x
        self.initial_y = y
示例#18
0
 def __init__(self, radius, fill_color):
     QtWidgets.QGraphicsEllipseItem.__init__(self, 0, 0, radius * 2,
                                             radius * 2)
     self.setPen(mask_pen)
     self.setBrush(QtGui.QBrush(fill_color))
     self.radius = radius
     self.x = 0
     self.y = 0
示例#19
0
 def paintEvent(self, event):
     """ Fills the panel background. """
     super(ReadOnlyPanel, self).paintEvent(event)
     if self.isVisible():
         # fill background
         painter = QtGui.QPainter(self)
         self._background_brush = QtGui.QBrush(self._color)
         painter.fillRect(event.rect(), self._background_brush)
示例#20
0
    def __init__(self, x, y, radius, fill_color):
        QtWidgets.QGraphicsEllipseItem.__init__(self, x - radius, y - radius, radius * 2, radius * 2)
        self.radius = radius
        self.setPen(mask_pen)
        self.setBrush(QtGui.QBrush(fill_color))

        self.center_x = x
        self.center_y = y
示例#21
0
 def set_fit_quality_to_default(self):
     self.fit_results_table.blockSignals(True)
     for i in range(self.get_number_of_entries()):
         fit_quality_item = self.fit_results_table.item(
             i, default_columns["Fit quality"])
         fit_quality_item.setForeground(QtGui.QBrush(QtCore.Qt.black))
         fit_quality_item.setText(default_fit_status)
     self.fit_results_table.blockSignals(False)
示例#22
0
    def _setBrush(self):
        """Selected cells are yellow when not current.
        The current cell is dark yellow when selected or grey when not
        selected.
        Other cells have no bg color by default, unless specified at
        instantiation (:attr:`bgcolor`)"""
        palette = self.palette()

        if self.selected:
            self.brush = QtGui.QBrush(self.selected_color)
        elif self.bgcolor is not None:
            self.brush = QtGui.QBrush(self.bgcolor)
        else:
            self.brush = QtGui.QBrush()
        palette.setBrush(self.backgroundRole(), self.brush)
        self.setPalette(palette)
        self.update()
示例#23
0
 def unhighlight(self):
     self._ellipseItem.setBrush(QtGui.QBrush(self._color))
     self._ellipseItem.setRect(
         -self.__radius,
         -self.__radius,
         self.__diameter,
         self.__diameter,
     )
示例#24
0
    def _validate(self):

        # Construct a list of all labels for the current dataset so that
        # we can check which ones are duplicates
        labels = [c.label for c in self._components_other[self.data]]
        labels.extend([c['label'] for c in self._state[self.data].values()])
        if len(labels) == 0:
            return
        label_count = Counter(labels)

        # It's possible that the duplicates are entirely for components not
        # shown in this editor, so we keep track here of whether an invalid
        # component has been found.
        invalid = False

        if label_count.most_common(1)[0][1] > 1:

            # If we are here, there are duplicates somewhere in the list
            # of components.

            brush_red = QtGui.QBrush(Qt.red)
            brush_black = QtGui.QBrush(Qt.black)

            self.list.blockSignals(True)

            for item in self.list:
                label = item.text(0)
                if label_count[label] > 1:
                    item.setForeground(0, brush_red)
                    invalid = True
                else:
                    item.setForeground(0, brush_black)

            self.list.blockSignals(False)

        if invalid:
            self.ui.label_status.setStyleSheet('color: red')
            self.ui.label_status.setText(
                'Error: some components have duplicate names')
            self.ui.button_ok.setEnabled(False)
            self.ui.combosel_data.setEnabled(False)
        else:
            self.ui.label_status.setStyleSheet('')
            self.ui.label_status.setText('')
            self.ui.button_ok.setEnabled(True)
            self.ui.combosel_data.setEnabled(True)
示例#25
0
    def __init__(self,
                 parent,
                 name="",
                 start_value=None,
                 max_value=100,
                 min_value=0,
                 font=None,
                 scale=1):
        QtWidgets.QGraphicsRectItem.__init__(self, parent)

        self.parent = parent
        self.name = name
        self.maxValue = max_value
        self.minValue = min_value
        self.format = "%.2f"

        self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))
        self.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255, 0)))

        self.text = QtWidgets.QGraphicsSimpleTextItem(self)
        if font is None:
            font = QtGui.QFont("", 11 / scale)
        else:
            font.setPointSize(11 / scale)
        self.text.setFont(font)
        self.text.setPos(0, -23)
        self.text.setBrush(QtGui.QBrush(QtGui.QColor("white")))

        self.sliderMiddel = QtWidgets.QGraphicsRectItem(self)
        self.sliderMiddel.setRect(QtCore.QRectF(0, 0, 100, 1))
        self.sliderMiddel.setPen(QtGui.QPen(QtGui.QColor("white")))

        path = QtGui.QPainterPath()
        path.addEllipse(-5, -5, 10, 10)
        self.slideMarker = QtWidgets.QGraphicsPathItem(path, self)
        self.slideMarker.setBrush(QtGui.QBrush(QtGui.QColor(255, 0, 0, 255)))

        self.setRect(QtCore.QRectF(-5, -5, 110, 10))
        self.dragged = False

        self.value = (self.maxValue + self.minValue) * 0.5
        if start_value is not None:
            self.value = start_value
        self.start_value = self.value
        self.setValue(self.value)
示例#26
0
    def paint(self, painter, option, index):
        """Renders the delegate for the item specified by index.

        This method handles specially the result returned by the model data()
        method for the Qt.BackgroundRole role. Typically, if the cell being
        rendered is selected then the data() returned value is ignored and the
        value set by the desktop (KDE, Gnome...) is used. We need to change
        that behavior as explained in the module docstring.

        The following properties of the style option are used for customising
        the painting: state (which holds the state flags), rect (which holds
        the area that should be used for painting) and palette (which holds the
        palette that should be used when painting)

        :Parameters:

        - `painter`: the painter used for rendering
        - `option`: the style option used for rendering
        - `index`: the index of the rendered item
        """

        # option.state is an ORed combination of flags
        if (option.state & QtWidgets.QStyle.State_Selected):
            model = index.model()
            buffer_start = model.start
            cell = index.model().selected_cell
            if ((index == cell['index']) and \
                    (buffer_start != cell['buffer_start'])):
                painter.save()
                self.initStyleOption(option, index)
                background = option.palette.color(QtGui.QPalette.Base)
                foreground = option.palette.color(QtGui.QPalette.Text)
                painter.setBrush(QtGui.QBrush(background))
                painter.fillRect(option.rect, painter.brush())
                painter.translate(option.rect.x() + 3, option.rect.y())
                painter.setBrush(QtGui.QBrush(foreground))
                painter.drawText(option.rect,
                                 QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop,
                                 model.data(index))
                painter.restore()
            else:
                QtWidgets.QStyledItemDelegate.paint(self, painter, option,
                                                    index)
        else:
            QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
示例#27
0
 def __init__(self, x, y, fill_color):
     QtWidgets.QGraphicsPolygonItem.__init__(self)
     self.setPen(mask_pen)
     self.setBrush(QtGui.QBrush(fill_color))
     self.arc_center = QtCore.QPointF(0, 0)
     self.arc_radius = 1
     self.phi_range = []
     self.vertices = []
     self.vertices.append(QtCore.QPointF(x, y))
 def _get_brush(self, color):
     """ Returns a brush for the color.
     """
     result = self._brushes.get(color)
     if result is None:
         qcolor = self._get_color(color)
         result = QtGui.QBrush(qcolor)
         self._brushes[color] = result
     return result
示例#29
0
 def highlight(self):
     self._ellipseItem.setBrush(QtGui.QBrush(self._color.lighter()))
     # make the port bigger to highlight it can accept the connection.
     self._ellipseItem.setRect(
         -self.__radius * 1.3,
         -self.__radius * 1.3,
         self.__diameter * 1.3,
         self.__diameter * 1.3,
     )
示例#30
0
 def _create_decoration(self, selection_start, selection_end):
     """ Creates the text occurences decoration """
     deco = TextDecoration(self.editor.document(), selection_start,
                           selection_end)
     deco.set_background(QtGui.QBrush(self.background))
     deco.set_outline(self._outline)
     deco.set_foreground(QtCore.Qt.black)
     deco.draw_order = 1
     return deco