Python PyQt5.QtGui.QLinearGradient() Examples

The following are 8 code examples for showing how to use PyQt5.QtGui.QLinearGradient(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .

Example 1
Project: MusicBox   Author: HuberTRoy   File: player.py    License: MIT License 5 votes vote down vote up
def paintEvent(self, event):
        painter = QPainter(self)
        painter.setFont(self.font)
        
        linear = QLinearGradient(QPoint(self.rect().topLeft()), QPoint(self.rect().bottomLeft()))
        linear.setStart(0, 10)
        linear.setFinalStop(0, 50)
        linear.setColorAt(0.1, QColor(14, 179, 255));
        linear.setColorAt(0.5, QColor(154, 232, 255));
        linear.setColorAt(0.9, QColor(14, 179, 255));
        
        linear2 = QLinearGradient(QPoint(self.rect().topLeft()), QPoint(self.rect().bottomLeft()))
        linear2.setStart(0, 10)
        linear2.setFinalStop(0, 50)
        linear2.setColorAt(0.1, QColor(222, 54, 4));
        linear2.setColorAt(0.5, QColor(255, 172, 116));
        linear2.setColorAt(0.9, QColor(222, 54, 4));
        
        painter.setPen(QColor(0, 0, 0, 200));
        painter.drawText(QRect(1, 1, self.screen.width(), 60), Qt.AlignHCenter | Qt.AlignVCenter, self.lyric)
        
        painter.setPen(QColor('transparent'));
        self.textRect = painter.drawText(QRect(0, 0, self.screen.width(), 60), Qt.AlignHCenter | Qt.AlignVCenter, self.lyric)

        painter.setPen(QPen(linear, 0))
        painter.drawText(self.textRect, Qt.AlignLeft | Qt.AlignVCenter, self.lyric)
        if self.intervel != 0:
            self.widthBlock = self.textRect.width()/(self.intervel/150.0)
        else:
            self.widthBlock = 0
        self.maskRect = QRectF(self.textRect.x(), self.textRect.y(), self.textRect.width(), self.textRect.height())
        self.maskRect.setWidth(self.maskWidth)
        painter.setPen(QPen(linear2, 0));
        painter.drawText(self.maskRect, Qt.AlignLeft | Qt.AlignVCenter, self.lyric) 
Example 2
Project: QMusic   Author: dragondjf   File: lrcwindow.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
def initData(self):
        self._hovered = False

        self.linear_gradient = QLinearGradient()
        self.linear_gradient.setStart(0, 10)
        self.linear_gradient.setFinalStop(0, 40)
    
        self.linear_gradient.setColorAt(0.1, QColor(14, 179, 255));
        self.linear_gradient.setColorAt(0.5, QColor(114, 232, 255));
        self.linear_gradient.setColorAt(1, QColor(14, 179, 255));

        self.mask_linear_gradient = QLinearGradient()
        self.mask_linear_gradient.setStart(0, 10)
        self.mask_linear_gradient.setFinalStop(0, 40)
        self.mask_linear_gradient.setColorAt(0.1, QColor(0, 100, 40))
        self.mask_linear_gradient.setColorAt(0.5, QColor(0, 72, 16))
        self.mask_linear_gradient.setColorAt(1, QColor(0, 255, 40))

        self.text = ""
        self.percentage = 0
        self.lyric_id = 0

        self.line1_text = ''
        self.line1_percentage = 0

        self.line2_text = ''
        self.line2_percentage = 0

        self.lrcfont = QFont()
        self.lrcfont.setPixelSize(30)
        self.setFont(self.lrcfont)

        self._lineMode = 1 
Example 3
Project: linux-show-player   Author: FrancescoCeruti   File: qdbmeter.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super().__init__(parent)

        db_range = abs(self.DB_MIN - self.DB_MAX)
        yellow = abs(self.DB_MIN + 20) / db_range  # -20 db
        red = abs(self.DB_MIN) / db_range          # 0 db

        self.grad = QLinearGradient()
        self.grad.setColorAt(0, QColor(0, 255, 0))            # Green
        self.grad.setColorAt(yellow, QColor(255, 255, 0))     # Yellow
        self.grad.setColorAt(red, QColor(255, 0, 0))          # Red

        self.reset() 
Example 4
Project: FeelUOwn   Author: feeluown   File: right_panel.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _draw_pixmap_overlay(self, painter, draw_width, draw_height, scrolled):
        painter.save()
        rect = QRect(0, 0, draw_width, draw_height)
        painter.translate(0, -scrolled)
        gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft())
        color = self.palette().color(QPalette.Base)
        if draw_height == self.height():
            gradient.setColorAt(0, add_alpha(color, 180))
            gradient.setColorAt(1, add_alpha(color, 230))
        else:
            if self._app.theme_mgr.theme == Light:
                gradient.setColorAt(0, add_alpha(color, 220))
                gradient.setColorAt(0.1, add_alpha(color, 180))
                gradient.setColorAt(0.2, add_alpha(color, 140))
                gradient.setColorAt(0.6, add_alpha(color, 140))
                gradient.setColorAt(0.8, add_alpha(color, 200))
                gradient.setColorAt(0.9, add_alpha(color, 240))
                gradient.setColorAt(1, color)
            else:
                gradient.setColorAt(0, add_alpha(color, 50))
                gradient.setColorAt(0.6, add_alpha(color, 100))
                gradient.setColorAt(0.8, add_alpha(color, 200))
                gradient.setColorAt(0.9, add_alpha(color, 240))
                gradient.setColorAt(1, color)
        painter.setBrush(gradient)
        painter.drawRect(rect)
        painter.restore() 
Example 5
Project: FeelUOwn   Author: feeluown   File: right_panel.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _draw_overlay(self, painter, draw_width, draw_height, scrolled):
        painter.save()
        rect = QRect(0, 0, draw_width, draw_height)
        painter.translate(0, -scrolled)
        gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft())
        gradient.setColorAt(0, self.palette().color(QPalette.Window))
        gradient.setColorAt(1, self.palette().color(QPalette.Base))
        painter.setBrush(gradient)
        painter.drawRect(rect)
        painter.restore() 
Example 6
Project: PyQt   Author: PyQt5   File: AreaChart.py    License: GNU General Public License v3.0 5 votes vote down vote up
def getSeries(self):
        # 创建Series
        series0 = QLineSeries(self)
        series1 = QLineSeries(self)

        # 添加数据
        series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) \
                << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5)
        series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) \
                << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3)

        # 创建区域图
        series = QAreaSeries(series0, series1)
        series.setName('Batman')

        # 画笔
        pen = QPen(0x059605)
        pen.setWidth(3)
        series.setPen(pen)

        # 设置画刷
        gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 1))
        gradient.setColorAt(0.0, QColor(0x3cc63c))
        gradient.setColorAt(1.0, QColor(0x26f626))
        gradient.setCoordinateMode(QGradient.ObjectBoundingMode)
        series.setBrush(gradient)

        return series 
Example 7
Project: mindfulness-at-the-computer   Author: mindfulness-at-the-computer   File: breathing_history_wt.py    License: GNU General Public License v3.0 4 votes vote down vote up
def add_new_breathing_rect(self, i_io: mc.mc_global.BreathingState, i_length: int=1):
        if i_io == mc.mc_global.BreathingState.breathing_out:
            self.new_cycle_bool = False

        # Rectangle
        xpos_ft = 0.0
        if len(self.in_breath_graphics_qgri_list) > 0:
            margin_int = SMALL_MARGIN_FT
            if self.new_cycle_bool:
                margin_int = LARGE_MARGIN_FT
            last_graphics_rect_item = self.in_breath_graphics_qgri_list[-1]
            xpos_ft = float(last_graphics_rect_item.rect().right() + margin_int)
            if i_io == mc.mc_global.BreathingState.breathing_out:
                xpos_ft = float(last_graphics_rect_item.rect().left())
        ypos_ft = -i_length
        if i_io == mc.mc_global.BreathingState.breathing_out:
            ypos_ft = 0.0

        t_drawrect = QtCore.QRectF(xpos_ft, ypos_ft, BAR_WIDTH_FT, i_length)

        # Gradient
        x_gradient = t_drawrect.x() - GRADIENT_IN_FT
        if i_io == mc.mc_global.BreathingState.breathing_out:
            x_gradient = t_drawrect.x() + GRADIENT_OUT_FT
        t_start_qpointf = QtCore.QPointF(x_gradient, t_drawrect.y())
        t_stop_qpointf = t_drawrect.bottomRight()
        t_linear_gradient = QtGui.QLinearGradient(t_start_qpointf, t_stop_qpointf)
        if i_io == mc.mc_global.BreathingState.breathing_in:
            t_linear_gradient.setColorAt(0.0, QtGui.QColor(0, 153, 0))
            t_linear_gradient.setColorAt(1.0, QtGui.QColor(0, 204, 0))
        else:
            t_linear_gradient.setColorAt(0.0, QtGui.QColor(51, 255, 51))
            t_linear_gradient.setColorAt(1.0, QtGui.QColor(102, 255, 102))

        # Adding rectangle with gradient
        t_graphics_rect_item = self.breathing_graphicsscene.addRect(
            t_drawrect,
            pen=QtGui.QPen(QtCore.Qt.NoPen),
            brush=QtGui.QBrush(t_linear_gradient)
        )
        if i_io == mc.mc_global.BreathingState.breathing_in:
            self.in_breath_graphics_qgri_list.append(t_graphics_rect_item)
        elif i_io == mc.mc_global.BreathingState.breathing_out:
            self.out_breath_graphics_qgri_list.append(t_graphics_rect_item)
        # -an alternative to storing this separately might be to use ".items" and check for type
        #  as there is a QGraphicsRectItem
        # -another alternative: **http://doc.qt.io/qt-5/qgraphicsitem.html#type** 
Example 8
Project: QMusic   Author: dragondjf   File: lrcwindow.py    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
def __init__(self):
        super(DQuickWidget, self).__init__()
        self.resize(1000, 100)

        self.setMinimumSize(100, 80)

        self.linear_gradient = QLinearGradient()
        self.linear_gradient.setStart(0, 10)
        self.linear_gradient.setFinalStop(0, 40)
    
        self.linear_gradient.setColorAt(0.1, QColor(14, 179, 255));
        self.linear_gradient.setColorAt(0.5, QColor(114, 232, 255));
        self.linear_gradient.setColorAt(0.9, QColor(14, 179, 255));

        self.mask_linear_gradient = QLinearGradient()
        self.mask_linear_gradient.setStart(0, 10)
        self.mask_linear_gradient.setFinalStop(0, 40)
        self.mask_linear_gradient.setColorAt(0.1, QColor(222, 54, 4))
        self.mask_linear_gradient.setColorAt(0.5, QColor(255, 72, 16))
        self.mask_linear_gradient.setColorAt(0.9, QColor(222, 54, 4))

        self.text = "PyQt 5.2版本最新发布了,Qt 库的Python绑定"

        self.font = QFont()
        self.font.setFamily("Times New Roman")
        self.font.setBold(True)
        self.font.setPixelSize(30)

        self.setFont(self.font)

        self.timer = QTimer(self)
        self.timer.setInterval(100)
        self.timer.timeout.connect(self.update)
        self.timer.start()

        self.textWidth = self.fontMetrics().width(self.text)
        self.textHeight = self.fontMetrics().height()

        self.p = 0.1

        self.button = QPushButton('1111', self)
        self.button.move(100, 0)
        self.button.resize(40, 40)

        self.toolBarHeight = 50