monaghans_creed
monaghans_creed

Reputation: 143

Multiple colors in background (transition)

Is there a way to have transitioning colors as background in PyQt? I tried using CSS's linear-gradient, which doesn't work

stylesheet = ("QWidget { background-color : linear-gradient(to right, red 50%, blue 50%);}")

How do I get it to work for me?

Upvotes: 2

Views: 2910

Answers (1)

Guimoute
Guimoute

Reputation: 4649

I manually specified the start and stop coordinates of the gradient using x1, x2 instead of to right and added the stop keywords.

stylesheet = "QWidget {background-color: qlineargradient(x1: 0, x2: 1, stop: 0 red, stop: 1 blue)}"

enter image description here

Or did you want a sharp transition like this?

stylesheet = "QWidget {background-color: qlineargradient(x1:0, x2:1, stop: 0.49 red, stop: 0.51 blue)}"

enter image description here

Upvotes: 5

Related Questions