python类QBrush()的实例源码

pixelator.py 文件源码 项目:pyqt5-example 作者: guinslym 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def paint(self, painter, option, index):
        if option.state & QStyle.State_Selected:
            painter.fillRect(option.rect, option.palette.highlight())

        size = min(option.rect.width(), option.rect.height())
        brightness = index.model().data(index, Qt.DisplayRole)
        radius = (size/2.0) - (brightness/255.0 * size/2.0)
        if radius == 0.0:
            return

        painter.save()
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        if option.state & QStyle.State_Selected:
            painter.setBrush(option.palette.highlightedText())
        else:
            painter.setBrush(QBrush(Qt.black))

        painter.drawEllipse(QRectF(
                            option.rect.x() + option.rect.width()/2 - radius,
                            option.rect.y() + option.rect.height()/2 - radius,
                            2*radius, 2*radius))

        painter.restore()
svgviewer.py 文件源码 项目:pyqt5-example 作者: guinslym 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, parent=None):
        super(SvgView, self).__init__(parent)

        self.renderer = SvgView.Native
        self.svgItem = None
        self.backgroundItem = None
        self.outlineItem = None
        self.image = QImage()

        self.setScene(QGraphicsScene(self))
        self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
        self.setDragMode(QGraphicsView.ScrollHandDrag)
        self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)

        # Prepare background check-board pattern.
        tilePixmap = QPixmap(64, 64)
        tilePixmap.fill(Qt.white)
        tilePainter = QPainter(tilePixmap)
        color = QColor(220, 220, 220)
        tilePainter.fillRect(0, 0, 32, 32, color)
        tilePainter.fillRect(32, 32, 32, 32, color)
        tilePainter.end()

        self.setBackgroundBrush(QBrush(tilePixmap))
transformations.py 文件源码 项目:pyqt5-example 作者: guinslym 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(Qt.white))

        painter.translate(66, 66)

        painter.save()
        self.transformPainter(painter)
        self.drawShape(painter)
        painter.restore()

        self.drawOutline(painter)

        self.transformPainter(painter)
        self.drawCoordinates(painter)
bubbleswidget.py 文件源码 项目:pyqt5-example 作者: guinslym 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def paintEvent(self, event):

        background = QRadialGradient(QPointF(self.rect().topLeft()), 500,
                QPointF(self.rect().bottomRight()))
        background.setColorAt(0, self.backgroundColor1)
        background.setColorAt(1, self.backgroundColor2)

        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(background))

        painter.setPen(self.pen)

        for bubble in self.bubbles:

            if QRectF(bubble.position - QPointF(bubble.radius, bubble.radius),
                      QSizeF(2*bubble.radius, 2*bubble.radius)).intersects(QRectF(event.rect())):
                bubble.drawBubble(painter)

        if self.newBubble:

            self.newBubble.drawBubble(painter)

        painter.end()
demo_app1.py 文件源码 项目:face-identification-tpe 作者: meownoid 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def draw_box(self, n, box, color, style, num):
        x1, y1, x2, y2 = box.left(), box.top(), box.right(), box.bottom()

        x1 = int(x1 * self.i_scale[n])
        y1 = int(y1 * self.i_scale[n])
        x2 = int(x2 * self.i_scale[n])
        y2 = int(y2 * self.i_scale[n])

        width = BASEWIDTH
        if style == 'match':
            width *= 2

        painter = QPainter(self.i_pixmap[n])
        painter.setPen(QPen(QBrush(color), width))
        painter.drawRect(x1, y1, x2 - x1, y2 - y1)
        painter.setPen(QPen(QBrush(TEXTCOLOR), TEXTWIDTH))
        painter.setFont(TEXTFONT)
        painter.drawText(x1, y2 + TEXTSIZE + 2 * BASEWIDTH, '{}: {}'.format(n + 1, num))
        painter.end()
        self.i_lbl[n].setPixmap(self.i_pixmap[n])
map.py 文件源码 项目:satellite-tracker 作者: lofaldli 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def brush(self, color=Qt.white, style=Qt.SolidPattern):
        return QBrush(color, style)
style.py 文件源码 项目:activity-browser 作者: LCA-ActivityBrowser 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def __init__(self):
        self.brushes = {}
        for key, values in self.COLOR_CODE.items():
            self.brushes.update({
                key: QtGui.QBrush(QtGui.QColor(*values))
            })
radar.py 文件源码 项目:echolocation 作者: hgross 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _add_latest_input_line(self, angle):
        """Adds a line to the graphic scene that visualizes a scanned angle"""
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        angle_1_rad = deg2rad(angle - self.measurement_angle/2.0)
        angle_2_rad = deg2rad(angle + self.measurement_angle/2.0)
        length = max(self.width(), self.height())

        start_point = (mx, my)
        p1 = (mx + length * math.cos(angle_1_rad), my + length * math.sin(angle_1_rad))
        p2 = (mx + length * math.cos(angle_2_rad), my + length * math.sin(angle_2_rad))

        gradient_start_point, gradient_end_point = (mx, my), (mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad))
        gradient = QLinearGradient(*gradient_start_point, *gradient_end_point)
        gradient.setColorAt(0, Qt.transparent)
        gradient.setColorAt(0.8, Qt.red)
        gradient.setColorAt(1, Qt.darkRed)

        triangle = QPolygonF()
        triangle.append(QPointF(*start_point))
        triangle.append(QPointF(*p1))
        triangle.append(QPointF(*p2))
        triangle.append(QPointF(*start_point))

        self.scene.addPolygon(triangle, pen=QPen(Qt.transparent), brush=QBrush(gradient))
radar.py 文件源码 项目:echolocation 作者: hgross 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _add_measurement(self, length, angle, added_time):
        """
        Adds a visualization for a measured distance to the scene
        :param length: length in cm
        :param angle: the angle
        """
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        ex, ey = mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad)

        age = time.time() - added_time
        age = age if age < self.fade_out_time else self.fade_out_time
        alpha_channel_value = scale((0, self.fade_out_time), (255, 0), age)
        assert 0 <= alpha_channel_value <= 255

        brush_color = QColor(self.measured_distances_color)
        brush_color.setAlpha(alpha_channel_value)
        brush = QBrush(brush_color)
        tpen = QPen(brush_color)

        self.scene.addLine(mx, my, ex, ey, pen=tpen)
        self.scene.addEllipse(ex-self.dot_width/2, ey-self.dot_width/2, self.dot_width, self.dot_width, pen=tpen, brush=brush)
gridcontrol.py 文件源码 项目:grid-control 作者: akej74 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def add_gpu_sensors(self):
        """Add selected temperature sensor(s) to the "Selected GPU sensor(s)" three widget."""
        items = [item for item in self.ui.treeWidgetHWMonData.selectedItems()]

        # The new items should have the tree widget itself as parent
        parent = self.ui.treeWidgetSelectedGPUSensors

        for item in items:
            sensor_item = QtWidgets.QTreeWidgetItem(parent)
            sensor_item.setText(0, item.text(0))
            sensor_item.setText(1, item.text(1))
            sensor_item.setForeground(0, QtGui.QBrush(QtCore.Qt.blue))  # Text color blue

        # Deselect all items in the HWMon tree widget after they have been added
        self.ui.treeWidgetHWMonData.clearSelection()
player.py 文件源码 项目:MusicPlayer 作者: HuberTRoy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, parent=None):
        super(PlayList, self).__init__()

        self.parent = parent

        self.setParent(self.parent.parent)
        self.setObjectName("PlayList")

        self.musicList = []

        self.currentRow = -1

        self.allRow = 0

        self.itemColor = QBrush(QColor.fromRgb(95,95,99))

        with open('QSS/playList.qss', 'r') as f:
            self.setStyleSheet(f.read())

        self.resize(574, 477)

        self.hide()

        self.setButtons()
        self.setLabels()
        self.setTables()

        self.setLayouts()

    # ???
port.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def setColor(self, color):
        self._color = color
        self._ellipseItem.setBrush(QtGui.QBrush(self._color))
port.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def unhighlight(self):
        self._ellipseItem.setBrush(QtGui.QBrush(self._color))
        self._ellipseItem.setRect(
            -self.__radius,
            -self.__radius,
            self.__diameter,
            self.__diameter,
            )

    # ===================
    # Connection Methods
    # ===================
canvas_variant.py 文件源码 项目:QtPropertyBrowserV2.6-for-pyqt5 作者: theall 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def addRectangle(self):
        item = QtCanvasRectangle(rand() % self.canvas.width(), rand() % self.canvas.height(), 50, 50, self.canvas)
        item.setBrush(QBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8)))
        item.setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 4))
        item.setZ(rand() % 256)
        item.show()
        return item
canvas_variant.py 文件源码 项目:QtPropertyBrowserV2.6-for-pyqt5 作者: theall 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def addEllipse(self):
        item = QtCanvasEllipse(50, 50, self.canvas)
        item.setBrush(QBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8)))
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setZ(rand() % 256)
        item.show()
        return item
canvas_typed.py 文件源码 项目:QtPropertyBrowserV2.6-for-pyqt5 作者: theall 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def addRectangle(self):
        item = QtCanvasRectangle(rand() % self.canvas.width(), rand() % self.canvas.height(), 50, 50, self.canvas)
        item.setBrush(QBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8)))
        item.setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 4))
        item.setZ(rand() % 256)
        item.show()
        return item
canvas_typed.py 文件源码 项目:QtPropertyBrowserV2.6-for-pyqt5 作者: theall 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def addEllipse(self):
        item = QtCanvasEllipse(50, 50, self.canvas)
        item.setBrush(QBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8)))
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setZ(rand() % 256)
        item.show()
        return item
wb_git_log_history_view.py 文件源码 项目:scm-workbench 作者: barry-scott 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__( self, app ):
        self.app = app

        self.debugLog = self.app.debug_options.debugLogLogHistory

        super().__init__()

        self.all_commit_nodes  = []
        self.all_tags_by_id = {}
        self.all_unpushed_commit_ids = set()

        self.__brush_is_tag = QtGui.QBrush( QtGui.QColor( 0, 0, 255 ) )
        self.__brush_is_unpushed = QtGui.QBrush( QtGui.QColor( 192, 0, 192 ) )
wb_svn_log_history_view.py 文件源码 项目:scm-workbench 作者: barry-scott 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__( self, app ):
        self.app = app

        self.debugLog = self.app.debug_options.debugLogLogHistory

        super().__init__()

        self.all_commit_nodes  = []
        self.all_tags_by_rev = {}

        self.__brush_is_tag = QtGui.QBrush( QtGui.QColor( 0, 0, 255 ) )
wb_scm_table_model.py 文件源码 项目:scm-workbench 作者: barry-scott 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__( self, app ):
        self.app = app

        self.debugLog = self.app.debug_options.debugLogTableModel

        super().__init__()

        self.scm_project_tree_node = None

        self.all_files = []
        self.all_included_files = None

        self.__brush_is_cached = QtGui.QBrush( QtGui.QColor( 255, 0, 255 ) )
        self.__brush_is_changed = QtGui.QBrush( QtGui.QColor( 0, 0, 255 ) )
        self.__brush_is_uncontrolled = QtGui.QBrush( QtGui.QColor( 0, 128, 0 ) )


问题


面经


文章

微信
公众号

扫码关注公众号