コード例 #1
0
        def refresh(self):
            value = round(self.player.value / self.player.best_value, 2)
            QRectF = QtCore.QRectF(self.parent.rect())
            gradient = QtGui.QLinearGradient(QRectF.topLeft(),
                                             QRectF.topRight())
            gradient.setColorAt(
                value - 0.001 if value > 0 else 0,
                QtGui.QColor(player_style(self.player.items).bg))
            gradient.setColorAt(value, QtGui.QColor('#000000'))
            gradient.setColorAt(value + 0.001 if value < 1 else 1,
                                QtGui.QColor('#000000'))

            brush = QtGui.QBrush(gradient)

            self.setBackground(brush)

            brush_fg = QtGui.QBrush(
                QtGui.QColor(player_style(self.player.items).fg))
            self.setForeground(brush_fg)

            icon = player_icon(self.player.items['weapon'])
            self.setToolTip('\n'.join([
                f'{k}: {map_name(v)}' for (k, v) in self.player.items.items()
                if v
            ]))
            if icon:
                self.setIcon(icon)
コード例 #2
0
 def save_schedule(self, item):
     """Save contents of schedule_table into schedule.json."""
     row = item.row()
     item = self.schedule_table.item
     self.schedule_table.blockSignals(True)
     try:
         b = QtGui.QBrush(QtCore.Qt.NoBrush)
         self.database.insert_or_update_schedule(
             int(self.schedule_table.item(row, 0).text()),
             self.schedule_table.item(row, 1).text(),
             self.schedule_table.item(row, 2).text(),
             self.schedule_table.item(row, 3).text(),
         )
         for i in range(self.schedule_table.columnCount()):
             self.schedule_table.item(row, i).setBackground(b)
     except sqlite3.IntegrityError:
         b = QtGui.QBrush(QtCore.Qt.SolidPattern)
         b.setColor(QtGui.QColor(150, 60, 60))
         for i in range(self.schedule_table.columnCount()):
             if self.schedule_table.item(row, i) is None:
                 self.schedule_table.setItem(row, i,
                                             QtWidgets.QTableWidgetItem())
             self.schedule_table.item(row, i).setBackground(b)
     finally:
         self.schedule_table.blockSignals(False)
コード例 #3
0
 def setText(self, txt, highlight=False):
     if txt:
         self.show()
         self.frameNumber.setText("%s" % txt)
         rect = self.frameNumber.boundingRect()
         self.setRect(self.frameNumber.boundingRect())
         if highlight:
             # paint with a different color when on
             # the first frame of a clip
             self.setBrush(
                 QtGui.QBrush(QtGui.QColor(55, 5, 0, 120))
             )
             self.frameNumber.setBrush(
                 QtGui.QBrush(QtGui.QColor(255, 250, 250, 255))
             )
         else:
             self.frameNumber.setBrush(
                 QtGui.QBrush(QtGui.QColor(25, 255, 10, 255))
             )
             self.setBrush(
                 QtGui.QBrush(QtGui.QColor(5, 55, 0, 120))
             )
         if self.position < 0:
             self.setX(-rect.width() - 2)
         else:
             self.setX(2)
     else:
         self.hide()
コード例 #4
0
 def background(self, background):
     self._background = background
     # info_string = self.infoString
     if background:
         # info_string += self.BG_SUFFIX
         self.setBrush(QtGui.QBrush(self.BG_COLOR, QtCore.Qt.BDiagPattern))
     else:
         # info_string = info_string.replace(self.BG_SUFFIX, "")
         self.setBrush(QtGui.QBrush(self.FG_COLOR, QtCore.Qt.SolidPattern))
コード例 #5
0
 def __init__(self, text, position, *args, **kwargs):
     super(FrameNumber, self).__init__(*args, **kwargs)
     self.frameNumber = QtWidgets.QGraphicsSimpleTextItem(self)
     self.frameNumber.setText("%s" % text)
     self.setBrush(QtGui.QBrush(QtGui.QColor(5, 55, 0, 255)))
     self.setPen(QtCore.Qt.NoPen)
     self.frameNumber.setBrush(QtGui.QBrush(QtGui.QColor(25, 255, 10, 255)))
     # if position < 0 then the frameNumber will appear on the left side
     # of the ruler
     self.position = position
コード例 #6
0
 def paint(self, painter, option, widget):
     painter.setPen(QtCore.Qt.NoPen)
     painter.setBrush(QtCore.Qt.darkGray)
     painter.drawEllipse(-12, -12, 30, 30)
     painter.setPen(QtGui.QPen(QtCore.Qt.black, 1))
     painter.setBrush(QtGui.QBrush(self.color))
     painter.drawEllipse(-15, -15, 30, 30)
コード例 #7
0
 def set_colors(self):
     self.setRectColor(color=self.colors["border"])
     if self.colors["fill"]:
         self.setBrush(
             QtGui.QBrush(self.colors["fill"], QtCore.Qt.SolidPattern))
     self.setupInfoTextItem(fontSize=self.text_opts["fontsize"],
                            color=self.colors["text"])
コード例 #8
0
 def __init__(self, *args, **kwargs):
     super(ClipItem, self).__init__(*args, **kwargs)
     self.setBrush(
         QtGui.QBrush(
             QtGui.QColor(168, 197, 255, 255) if self.item.
             enabled else QtGui.QColor(100, 100, 100, 255)))
     self.source_name_label.setText(self.item.name)
コード例 #9
0
    def __init__(self, height, composition, *args, **kwargs):

        poly = QtGui.QPolygonF()
        poly.append(QtCore.QPointF(0.5 * RULER_SIZE, -0.5 * RULER_SIZE))
        poly.append(QtCore.QPointF(0.5 * RULER_SIZE, 0.5 * RULER_SIZE))
        poly.append(QtCore.QPointF(0, RULER_SIZE))
        poly.append(QtCore.QPointF(0, height))
        poly.append(QtCore.QPointF(0, RULER_SIZE))
        poly.append(QtCore.QPointF(-0.5 * RULER_SIZE, 0.5 * RULER_SIZE))
        poly.append(QtCore.QPointF(-0.5 * RULER_SIZE, -0.5 * RULER_SIZE))
        super(Ruler, self).__init__(poly, *args, **kwargs)

        # to retrieve tracks and its children
        self.composition = composition
        self.setBrush(QtGui.QBrush(QtGui.QColor(50, 255, 20, 255)))

        self.setAcceptHoverEvents(True)
        self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, True)
        self.setFlag(QtWidgets.QGraphicsItem.ItemIsFocusable, True)

        self.labels = list()
        self._time_space = self.time_space_default
        self._bounded_data = collections.namedtuple(
            "bounded_data", ["f", "is_bounded", "is_tail", "is_head"])
        self.init()
コード例 #10
0
 def __init__(self, track, *args, **kwargs):
     super(Track, self).__init__(*args, **kwargs)
     self.track = track
     self.widget_items = []
     self.track_name_item = None
     self.setBrush(QtGui.QBrush(QtGui.QColor(43, 52, 59, 255)))
     self._populate()
コード例 #11
0
 def __init__(self, *args, **kwargs):
     super(TimeSlider, self).__init__(*args, **kwargs)
     self.setBrush(QtGui.QBrush(QtGui.QColor(64, 78, 87, 255)))
     pen = QtGui.QPen()
     pen.setWidth(0)
     self.setPen(pen)
     self._ruler = None
コード例 #12
0
 def draw_roi_polygons(self, roi_id, polygons, roi_color=None):
     """
     Draw ROI polygons on the image slice
     :param roi_id: ROI number
     :param polygons: List of ROI polygons
     :param roi_color: colors for ROIs used when displaying selected rois in
     manipulate ROI window
     """
     if roi_color is None:
         color = self.roi_color[roi_id]
     else:
         color = roi_color[roi_id]
     with open(data_path('line&fill_configuration'), 'r') as stream:
         elements = stream.readlines()
         if len(elements) > 0:
             roi_line = int(elements[0].replace('\n', ''))
             roi_opacity = int(elements[1].replace('\n', ''))
             line_width = float(elements[4].replace('\n', ''))
         else:
             roi_line = 1
             roi_opacity = 10
             line_width = 2.0
         stream.close()
     roi_opacity = int((roi_opacity / 100) * 255)
     color.setAlpha(roi_opacity)
     pen_color = QtGui.QColor(color.red(), color.green(), color.blue())
     pen = self.get_qpen(pen_color, roi_line, line_width)
     for i in range(len(polygons)):
         self.scene.addPolygon(polygons[i], pen, QtGui.QBrush(color))
コード例 #13
0
    def draw_roi(self):
        """ Draw the new ROI """
        # Get the new ROI's name
        new_roi_name = self.new_roi_name_line_edit.text()

        # Check if the new ROI contour is None
        if self.new_ROI_contours is None:
            return

        # Get the info required to draw the new ROI
        slider_id = self.dicom_preview.slider.value()
        curr_slice = self.patient_dict_container.get("dict_uid")[slider_id]

        # Calculate the new ROI's polygon
        dict_ROI_contours = {}
        dict_ROI_contours[new_roi_name] = self.new_ROI_contours
        polygons = ROI.calc_roi_polygon(new_roi_name, curr_slice,
                                        dict_ROI_contours)

        # Set the new ROI color
        color = QtGui.QColor()
        color.setRgb(90, 250, 175, 200)
        pen_color = QtGui.QColor(color.red(), color.green(), color.blue())
        pen = QtGui.QPen(pen_color)
        pen.setStyle(QtCore.Qt.PenStyle(1))
        pen.setWidthF(2.0)

        # Draw the new ROI
        self.dicom_preview.update_view()
        for i in range(len(polygons)):
            self.dicom_preview.scene.addPolygon(polygons[i], pen,
                                                QtGui.QBrush(color))
コード例 #14
0
    def __init__(self, item, timeline_range, *args, **kwargs):
        super(BaseItem, self).__init__(*args, **kwargs)
        self.item = item
        self.timeline_range = timeline_range

        # List of otio.core.SerializableObject
        # it excludes decorator widgets as QLabel ...
        self._otio_sub_items = list()

        self.setFlags(QtWidgets.QGraphicsItem.ItemIsSelectable)
        self.setBrush(QtGui.QBrush(QtGui.QColor(180, 180, 180, 255)))

        pen = QtGui.QPen()
        pen.setWidth(0)
        pen.setCosmetic(True)
        self.setPen(pen)

        self.source_in_label = QtWidgets.QGraphicsSimpleTextItem(self)
        self.source_out_label = QtWidgets.QGraphicsSimpleTextItem(self)
        self.source_name_label = QtWidgets.QGraphicsSimpleTextItem(self)

        self._add_markers()
        self._add_effects()
        self._set_labels()
        self._set_tooltip()

        self.x_value = 0.0
        self.current_x_offset = TRACK_NAME_WIDGET_WIDTH
コード例 #15
0
 def init_view(self):
     """
     Create a view widget for DICOM image.
     """
     self.view.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform)
     background_brush = QtGui.QBrush(QtGui.QColor(0, 0, 0), QtCore.Qt.SolidPattern)
     self.view.setBackgroundBrush(background_brush)
     self.view.setGeometry(QtCore.QRect(0, 0, 877, 517))
コード例 #16
0
 def _makePixmap(self, width, height):
     pixmap = QtGui.QPixmap(width, height)
     style = int(
         self.brushComboBox.itemData(self.brushComboBox.currentIndex()))
     brush = QtGui.QBrush(self.color, QtCore.Qt.BrushStyle(style))
     painter = QtGui.QPainter(pixmap)
     painter.fillRect(pixmap.rect(), QtCore.Qt.white)
     painter.fillRect(pixmap.rect(), brush)
     return pixmap
コード例 #17
0
ファイル: data_model.py プロジェクト: davidfokkema/tailor
    def data(self, index, role):
        """Return (attributes of) the data.

        This method is called by the table view to request data points or its
        attributes. For each table cell multiple calls are made, one for each
        'role'. The role indicates the type of data that is requested. For
        example, the DisplayRole indicates a string is requested to display in
        the cell. Also, a BackgroundRole indicates that the background color for
        the cell is requested. You can use this to indicate different types of
        data, e.g. calculated or input data.

        If a role is requested that is not implemented an invalid QVariant
        (None) is returned.

        Args:
            index: a QModelIndex referencing the requested data item.
            role: an ItemDataRole to indicate what type of information is
                requested.

        Returns: The requested data or an invalid QVariant (None).
        """
        row = index.row()
        col = index.column()

        if role in [QtCore.Qt.DisplayRole, QtCore.Qt.EditRole]:
            # request for the data itself
            value = self._data.iat[row, col]
            if np.isnan(value) and not self.is_calculated_column(col):
                # NaN in a data column, show as empty
                return ""
            else:
                return f"{value:.10g}"
        elif role == QtCore.Qt.BackgroundRole:
            # request for the background fill of the cell
            if self.is_calculated_column(col):
                if self.is_calculated_column_valid(col):
                    # Yellow
                    return QtGui.QBrush(QtGui.QColor(255, 255, 200))
                else:
                    # Red
                    return QtGui.QBrush(QtGui.QColor(255, 200, 200))
        # not implemented, return an invalid QVariant (None) per the docs
        # See Qt for Python docs -> Considerations -> API Changes
        return None
コード例 #18
0
    def roi_display(self):
        """
        Display ROI structures on the DICOM Image.
        """
        slider_id = self.slider.value()
        curr_slice = self.patient_dict_container.get("dict_uid")[slider_id]

        selected_rois = self.patient_dict_container.get("selected_rois")
        rois = self.patient_dict_container.get("rois")
        selected_rois_name = []
        for roi in selected_rois:
            selected_rois_name.append(rois[roi]['name'])

        for roi in selected_rois:
            roi_name = rois[roi]['name']

            if roi_name not in self.patient_dict_container.get("dict_polygons").keys():
                new_dict_polygons = self.patient_dict_container.get("dict_polygons")
                new_dict_polygons[roi_name] = {}
                dict_rois_contours = get_contour_pixel(self.patient_dict_container.get("raw_contour"),
                                                       selected_rois_name, self.patient_dict_container.get("pixluts"),
                                                       curr_slice)
                polygons = self.calc_roi_polygon(roi_name, curr_slice, dict_rois_contours)
                new_dict_polygons[roi_name][curr_slice] = polygons
                self.patient_dict_container.set("dict_polygons", new_dict_polygons)

            elif curr_slice not in self.patient_dict_container.get("dict_polygons")[roi_name].keys():
                new_dict_polygons = self.patient_dict_container.get("dict_polygons")
                dict_rois_contours = get_contour_pixel(self.patient_dict_container.get("raw_contour"),
                                                       selected_rois_name, self.patient_dict_container.get("pixluts"),
                                                       curr_slice)
                polygons = self.calc_roi_polygon(roi_name, curr_slice, dict_rois_contours)
                new_dict_polygons[roi_name][curr_slice] = polygons
                self.patient_dict_container.set("dict_polygons", new_dict_polygons)

            else:
                polygons = self.patient_dict_container.get("dict_polygons")[roi_name][curr_slice]

            color = self.patient_dict_container.get("roi_color_dict")[roi]
            with open(resource_path('data/line&fill_configuration'), 'r') as stream:
                elements = stream.readlines()
                if len(elements) > 0:
                    roi_line = int(elements[0].replace('\n', ''))
                    roi_opacity = int(elements[1].replace('\n', ''))
                    line_width = float(elements[4].replace('\n', ''))
                else:
                    roi_line = 1
                    roi_opacity = 10
                    line_width = 2.0
                stream.close()
            roi_opacity = int((roi_opacity / 100) * 255)
            color.setAlpha(roi_opacity)
            pen = self.get_qpen(color, roi_line, line_width)
            for i in range(len(polygons)):
                self.scene.addPolygon(polygons[i], pen, QtGui.QBrush(color))
コード例 #19
0
 def inactivate_before_index(self, index: int) -> None:
     """Make all the items before `index` grey, and after, the default color."""
     assert index <= self.table.row_count, f"Index {index} out of range."
     grey_color = QtGui.QColor(150, 150, 150)
     for row in range(0, index):
         for column in range(0, self.table.column_count):
             self.table.item(row, column).set_foreground(grey_color)
     default_brush = QtGui.QBrush()
     for row in range(index, self.table.row_count):
         for column in range(0, self.table.column_count):
             self.table.item(row, column).set_foreground(default_brush)
コード例 #20
0
    def drawFocusRect(self, painter):
        self.focusbrush = QtGui.QBrush()
        self.focuspen = QtGui.QPen(QtCore.Qt.DashLine)
        self.focuspen.setColor(QtCore.Qt.darkGray)
        self.focuspen.setWidthF(1.0)
        # no pen thickness change when zoomed
        self.focuspen.setCosmetic(True)  # no thickness change when zoomed
        painter.setBrush(self.focusbrush)
        painter.setPen(self.focuspen)

        painter.drawRect(self.boundingRect())
コード例 #21
0
 def _get_icon(self):
     pixmap = QtGui.QPixmap(self._size, self._size)
     pixmap.fill(QtCore.Qt.transparent)
     painter = QtGui.QPainter(pixmap)
     color = QtCore.Qt.green
     brush = QtGui.QBrush(color)
     painter.setBrush(brush)
     painter.setPen(QtCore.Qt.NoPen)
     painter.drawEllipse(0, 0, self._size, self._size)
     painter.end()
     return QtGui.QIcon(pixmap)
コード例 #22
0
    def __init__(self, composition, *args, **kwargs):
        super(CompositionWidget, self).__init__(*args, **kwargs)
        self.composition = composition
        self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(33, 33, 33)))

        self._adjust_scene_size()
        self._add_tracks()
        self._add_time_slider()
        self._add_markers()
        self._ruler = self._add_ruler()

        self._data_cache = self._cache_tracks()
コード例 #23
0
 def setupResizeBox(self):
     self.resizeBox = QtWidgets.QGraphicsRectItem(self)
     self.resizeBox.setRect(self.rect().x(), self.rect().y(), 0, 0)
     self.resizeBoxPenWidth = 0
     penColor = copy.copy(self.resizeBoxColor)
     penColor.setAlpha(255)
     pen = QtGui.QPen(penColor)
     pen.setWidthF(self.resizeBoxPenWidth)
     self.resizeBox.setPen(pen)
     self.resizeBox.setBrush(QtGui.QBrush(self.resizeBoxColor))
     self.resizeBox.setFlag(QtWidgets.QGraphicsItem.ItemStacksBehindParent,
                            True)
コード例 #24
0
    def __init__(self, marker, *args, **kwargs):
        self.item = marker

        poly = QtGui.QPolygonF()
        poly.append(QtCore.QPointF(0.5 * MARKER_SIZE, -0.5 * MARKER_SIZE))
        poly.append(QtCore.QPointF(0.5 * MARKER_SIZE, 0.5 * MARKER_SIZE))
        poly.append(QtCore.QPointF(0, MARKER_SIZE))
        poly.append(QtCore.QPointF(-0.5 * MARKER_SIZE, 0.5 * MARKER_SIZE))
        poly.append(QtCore.QPointF(-0.5 * MARKER_SIZE, -0.5 * MARKER_SIZE))
        super(Marker, self).__init__(poly, *args, **kwargs)

        self.setFlags(QtWidgets.QGraphicsItem.ItemIsSelectable)
        self.setBrush(QtGui.QBrush(QtGui.QColor(121, 212, 177, 255)))
コード例 #25
0
    def __init__(self, item, timeline_range, rect, *args, **kwargs):
        rect.setHeight(TRANSITION_HEIGHT)
        super(TransitionItem, self).__init__(item, timeline_range, rect, *args,
                                             **kwargs)
        self.setBrush(QtGui.QBrush(QtGui.QColor(237, 228, 148, 255)))
        self.setY(TRACK_HEIGHT - TRANSITION_HEIGHT)
        self.setZValue(2)

        # add extra bit of shading
        shading_poly_f = QtGui.QPolygonF()
        shading_poly_f.append(QtCore.QPointF(0, 0))
        shading_poly_f.append(QtCore.QPointF(rect.width(), 0))
        shading_poly_f.append(QtCore.QPointF(0, rect.height()))

        shading_poly = QtWidgets.QGraphicsPolygonItem(shading_poly_f,
                                                      parent=self)
        shading_poly.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 30)))

        try:
            shading_poly.setPen(QtCore.Qt.NoPen)
        except TypeError:
            shading_poly.setPen(QtCore.Qt.transparent)
コード例 #26
0
    def backgroundButtonGroupClicked(self, button):
        buttons = self.backgroundButtonGroup.buttons()
        for myButton in buttons:
            if myButton != button:
                button.setChecked(False)

        text = button.text()
        if text == "Blue Grid":
            self.scene.setBackgroundBrush(
                QtGui.QBrush(QtGui.QPixmap(':/images/background1.png')))
        elif text == "White Grid":
            self.scene.setBackgroundBrush(
                QtGui.QBrush(QtGui.QPixmap(':/images/background2.png')))
        elif text == "Gray Grid":
            self.scene.setBackgroundBrush(
                QtGui.QBrush(QtGui.QPixmap(':/images/background3.png')))
        else:
            self.scene.setBackgroundBrush(
                QtGui.QBrush(QtGui.QPixmap(':/images/background4.png')))

        self.scene.update()
        self.view.update()
コード例 #27
0
ファイル: main.py プロジェクト: anrienexe/gui
 def __init__(self, parent):
     super(PhotoViewer, self).__init__(parent)
     self._zoom = 0
     self._empty = True
     self._scene = QtWidgets.QGraphicsScene(self)
     self._photo = QtWidgets.QGraphicsPixmapItem()
     self._scene.addItem(self._photo)
     self.setScene(self._scene)
     self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
     self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
     self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
     self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
     self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(30, 30, 30)))
     self.setFrameShape(QtWidgets.QFrame.NoFrame)
コード例 #28
0
    def isodose_display(self):
        """
        Display isodoses on the DICOM Image.
        """
        slider_id = self.slider.value()
        curr_slice_uid = self.patient_dict_container.get("dict_uid")[slider_id]
        z = self.patient_dict_container.dataset[
            slider_id].ImagePositionPatient[2]
        dataset_rtdose = self.patient_dict_container.dataset['rtdose']
        grid = get_dose_grid(dataset_rtdose, float(z))

        if not (grid == []):
            # sort selected_doses in ascending order so that the high dose isodose washes
            # paint over the lower dose isodose washes
            for sd in sorted(
                    self.patient_dict_container.get("selected_doses")):
                dose_level = sd * self.patient_dict_container.get("rx_dose_in_cgray") / \
                    (dataset_rtdose.DoseGridScaling * 10000)
                contours = measure.find_contours(grid, dose_level)

                polygons = self.calc_dose_polygon(
                    self.patient_dict_container.get("dose_pixluts")
                    [curr_slice_uid], contours)

                brush_color = self.iso_color[sd]
                with open(data_path('line&fill_configuration'), 'r') as stream:
                    elements = stream.readlines()
                    if len(elements) > 0:
                        iso_line = int(elements[2].replace('\n', ''))
                        iso_opacity = int(elements[3].replace('\n', ''))
                        line_width = float(elements[4].replace('\n', ''))
                    else:
                        iso_line = 2
                        iso_opacity = 5
                        line_width = 2.0
                    stream.close()
                iso_opacity = int((iso_opacity / 100) * 255)
                brush_color.setAlpha(iso_opacity)
                pen_color = QtGui.QColor(brush_color.red(),
                                         brush_color.green(),
                                         brush_color.blue())
                pen = self.get_qpen(pen_color, iso_line, line_width)
                for i in range(len(polygons)):
                    self.scene.addPolygon(polygons[i], pen,
                                          QtGui.QBrush(brush_color))
コード例 #29
0
    def setupScene(self):
        self.m_scene.setSceneRect(-300, -200, 600, 460)

        linearGrad = QtGui.QLinearGradient(QtCore.QPointF(-100, -100),
                                           QtCore.QPointF(100, 100))
        linearGrad.setColorAt(0, QtGui.QColor(255, 255, 255))
        linearGrad.setColorAt(1, QtGui.QColor(192, 192, 255))
        self.setBackgroundBrush(linearGrad)

        radialGrad = QtGui.QRadialGradient(30, 30, 30)
        radialGrad.setColorAt(0, QtCore.Qt.yellow)
        radialGrad.setColorAt(0.2, QtCore.Qt.yellow)
        radialGrad.setColorAt(1, QtCore.Qt.transparent)

        pixmap = QtGui.QPixmap(60, 60)
        pixmap.fill(QtCore.Qt.transparent)

        painter = QtGui.QPainter(pixmap)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(radialGrad)
        painter.drawEllipse(0, 0, 60, 60)
        painter.end()

        self.m_lightSource = self.m_scene.addPixmap(pixmap)
        self.m_lightSource.setZValue(2)

        for i in range(-2, 3):
            for j in range(-2, 3):
                if (i + j) & 1:
                    item = QtWidgets.QGraphicsEllipseItem(0, 0, 50, 50)
                else:
                    item = QtWidgets.QGraphicsRectItem(0, 0, 50, 50)

                item.setPen(QtGui.QPen(QtCore.Qt.black, 1))
                item.setBrush(QtGui.QBrush(QtCore.Qt.white))

                effect = QtWidgets.QGraphicsDropShadowEffect(self)
                effect.setBlurRadius(8)
                item.setGraphicsEffect(effect)
                item.setZValue(1)
                item.setPos(i * 80, j * 80)
                self.m_scene.addItem(item)
                self.m_items.append(item)
コード例 #30
0
    def paint(self, painter, option, widget):
        # this function must be overwritten when subclassing QGraphicsItem

        painter.setBrush(self.brush)
        painter.setPen(self.pen)
        painter.setFont(self.font)

        # draw the gridline aliased, that makes them looking "sharper"
        if self.method == 'drawPolyline':
            painter.setRenderHint(QtGui.QPainter.Antialiasing, False)
        else:
            painter.setRenderHint(QtGui.QPainter.Antialiasing, True)

        # care for difference between objects and text
        # i.e. normally y-coordinates go top down
        # to make a normal coordinate system y-axis is swapped in PGraphicsview
        # since PyQT does this automatically for text in the original setup
        # the text here needs to be swapped back to be printed correctly
        # scale on text items therefore in PGraphicsitemsCollection
        # gets scale (1, -1), all other items get scale (1, 1)
        painter.scale(self.scale[0], self.scale[1])

        # call module painter with its method given by string in self.method
        # args are arguments to method
        # painter is a QPainter instance
        # depending on the method a variable number of arguments is needed
        # example:
        # if self.method = 'drawEllipse'
        # and self.args = QRectF(x, y, w, h)
        # the call to painter would render as:
        # painter.drawEllipse(*self.args)
        getattr(painter, self.method)(*self.args)

        if self.isSelected():
            # draw rectangle around selected item
            self.drawFocusRect(painter)

            # make selected item opaque
            color = self.brush.color()
            # color.setAlpha(80)
            brush = QtGui.QBrush(color)
            painter.setBrush(brush)