Skip to content

LinearGradient

Base classes

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

⋔ Inheritance diagram

graph TD
  3687455248["gui.LinearGradient"]
  2029929632["gui.GradientMixin"]
  2751680898["builtins.object"]
  1153711279["QtGui.QLinearGradient"]
  4233856040["QtGui.QGradient"]
  37984305["Shiboken.Object"]
  2029929632 --> 3687455248
  2751680898 --> 2029929632
  1153711279 --> 3687455248
  4233856040 --> 1153711279
  37984305 --> 4233856040
  2751680898 --> 37984305

🛈 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, final_stop = self.start(), self.finalStop()
        x1, y1, x2, y2 = stop.x(), stop.y(), final_stop.x(), final_stop.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, final_stop = self.start(), self.finalStop()
    x1, y1, x2, y2 = stop.x(), stop.y(), final_stop.x(), final_stop.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})"
    )

:fa-brands-github: Show source on GitHub