Skip to content

LinearGradient

Qt Base Class: QLinearGradient

Signature: QLinearGradient(self) -> None QLinearGradient(self, QLinearGradient: PySide6.QtGui.QLinearGradient) -> None QLinearGradient(self, start: Union[PySide6.QtCore.QPointF, PySide6.QtCore.QPoint, PySide6.QtGui.QPainterPath.Element], finalStop: Union[PySide6.QtCore.QPointF, PySide6.QtCore.QPoint, PySide6.QtGui.QPainterPath.Element]) -> None QLinearGradient(self, xStart: float, yStart: float, xFinalStop: float, yFinalStop: float) -> None

Base classes

Name Children Inherits
GradientMixin
prettyqt.gui.gradient
QLinearGradient
PySide6.QtGui
QLinearGradient(self) -> None

⋔ Inheritance diagram

graph TD
  1473245600208["gui.LinearGradient"]
  1473245598256["gui.GradientMixin"]
  140713234304496["builtins.object"]
  1473300123360["QtGui.QLinearGradient"]
  1473300122384["QtGui.QGradient"]
  1473291690208["Shiboken.Object"]
  1473245598256 --> 1473245600208
  140713234304496 --> 1473245598256
  1473300123360 --> 1473245600208
  1473300122384 --> 1473300123360
  1473291690208 --> 1473300122384
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: GradientMixin, QLinearGradient

Used in combination with QBrush to specify a linear gradient brush.

Source code in prettyqt\gui\lineargradient.py
class LinearGradient(gui.GradientMixin, gui.QLinearGradient):
    """Used in combination with QBrush to specify a linear gradient brush."""

    def __repr__(self):
        return get_repr(self, self.get_start(), self.get_final_stop())

    def get_start(self) -> core.PointF:
        return core.PointF(self.start())

    def get_final_stop(self) -> core.PointF:
        return core.PointF(self.finalStop())

    def get_css(self) -> str:
        """Convert gradient to a CSS string. Can be used for stylesheets."""
        stop, finalStop = self.start(), self.finalStop()
        x1, y1, x2, y2 = stop.x(), stop.y(), finalStop.x(), finalStop.y()
        stops = self.stops()
        stops = "\n".join(f"    stop: {stop:f} {color.name()}" for stop, color in stops)
        spread = self.get_spread()
        return (
            "qlineargradient(\n"
            f"    x1: {x1}, y1: {y1}, x2: {x2}, y2: {y2}, spread:{spread},\n"
            f"{stops})"
        )

get_css() -> str

Convert gradient to a CSS string. Can be used for stylesheets.

Source code in prettyqt\gui\lineargradient.py
def get_css(self) -> str:
    """Convert gradient to a CSS string. Can be used for stylesheets."""
    stop, finalStop = self.start(), self.finalStop()
    x1, y1, x2, y2 = stop.x(), stop.y(), finalStop.x(), finalStop.y()
    stops = self.stops()
    stops = "\n".join(f"    stop: {stop:f} {color.name()}" for stop, color in stops)
    spread = self.get_spread()
    return (
        "qlineargradient(\n"
        f"    x1: {x1}, y1: {y1}, x2: {x2}, y2: {y2}, spread:{spread},\n"
        f"{stops})"
    )