In this we article we are going to have Introduction To PyQt5 QRadialGradient Color.
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush.Simple radial gradients interpolate colors between a focal point and end points on a circle surrounding it. Extended radial gradients interpolate colors between a focal circle and a center circle. Points outside the cone defined by the two circles will be transparent. For simple radial gradients the focal point is adjusted to lie inside the center circle, whereas the focal point can have any position in an extended radial gradient.
More article on QPainter class In PyQt5
Also you can check more Python GUI articles in the below links
1: Kivy GUI Development Tutorials
2: TKinter GUI Development Tutorials
4: wxPython GUI Development Tutorials
5: PyQt5 GUI Development Tutorials
So this the complete code for PyQt5 QRadialGradient Color
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
from PyQt5 import QtGui from PyQt5.QtWidgets import QApplication, QMainWindow import sys import sys from PyQt5.QtGui import QPainter, QBrush, QPen, QRadialGradient from PyQt5.QtCore import Qt, QPoint class Window(QMainWindow): def __init__(self): super().__init__() self.title = "PyQt5 Radial Gradient" self.top = 100 self.left = 100 self.width = 680 self.height = 500 self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon("icon.png")) self.setWindowTitle(self.title) self.setGeometry(self.top, self.left, self.width, self.height) self.show() def paintEvent(self, event): painter = QPainter(self) painter.setPen(QPen(Qt.black, 4, Qt.SolidLine)) radialGradient = QRadialGradient(QPoint(100,100), 100) # center point and radious radialGradient.setColorAt(0.4, Qt.white) radialGradient.setColorAt(0.8, Qt.green) radialGradient.setColorAt(1.0, Qt.black) painter.setBrush(QBrush(radialGradient)) painter.drawRect(10,10, 200,200) App = QApplication(sys.argv) window = Window() sys.exit(App.exec()) |
This method is for drawing of our shapes in PyQt5, in this method first we have created a
QPainter object and after that we have created QRadialGradient object and we have set the
color for QRadialGradient.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def paintEvent(self, event): painter = QPainter(self) painter.setPen(QPen(Qt.black, 4, Qt.SolidLine)) radialGradient = QRadialGradient(QPoint(100,100), 100) # center point and radious radialGradient.setColorAt(0.4, Qt.white) radialGradient.setColorAt(0.8, Qt.green) radialGradient.setColorAt(1.0, Qt.black) painter.setBrush(QBrush(radialGradient)) painter.drawRect(10,10, 200,200) |
Run the complete code and this will be the result
Also you can watch the complete video for this article
Subscribe and Get Free Video Courses & Articles in your Email
Havіng read this I thought it was very enliɡhtening.
I apprecіаte you spending some time and enerɡy to put
tһis article together. I once again find myseⅼf spending a significant amount of time
both reading and posting comments. But so what, it was still worthwhile!
Thanks from your thought