How To Draw Polygon In Python With PyQt5 (QPainter Class)

In this PyQt5 article i want to show you How To Draw Polygon In Python With PyQt5 (QPainter Class). QPainter class is  is used for drawing different shapes in PyQt5. before this we had a complete introduction to QPainter class so you can check my previous articles in the below links.

 

 

Learn More on Qt5

1: How To Draw Rectangle In PyQt5 With QPainter Class

2: How To Draw Ellipse in PyQt5 With QPainter Class

 

 

 

Also you can check more Python GUI articles in the below links

1: Kivy GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Psyide2 GUI Development 

4: wxPython GUI Development Tutorials

5: PyQt5 GUI Development Tutorials

 

 

 

This is the complete source code for How To Draw Polygon In Python With PyQt5 (QPainter Class)

 

 

 

 

These are the imported classes that we are using in this article.

 

 

 

So now this is our main Window class that extends from QMainWindow. and in the constructor of the class we need to initialize some window requirements.

 

 

 

In here we are going to set our window title, window icon and window geometry, also we need to show our window in here.

 

 

 

 

So in QPainter class when we are going to do drawing we need to use paintEvent() method. in this method first we have created the QPainter class object and we have set the QBrush and QPen for our QPainter class and for drawing of QPolygon we need some QPoints and at the end we draw our polygon

 

 

 

 

Run the complete code and this will be the result

How To Draw Polygon In Python With PyQt5 (QPainter Class)
How To Draw Polygon In Python With PyQt5 (QPainter Class)

Subscribe and Get Free Video Courses & Articles in your Email

 

1 thought on “How To Draw Polygon In Python With PyQt5 (QPainter Class)”

  1. Hey Parwiz, please help me out. its been only one month that I have started learning Qt. Now i need to draw an arrow on an image using mouse click events. I know how to draw rectangle, ellipse, line using the available libraries, but my requirement is to start drawing the arrow once the mouse is pressed and end the drawing when the mouse is released. I hope my querry is clear. please please please help me out. I am stuck at this and tried several ways, but failed. Hope you l reply.

Comments are closed.

Codeloop
Share via
Copy link
Powered by Social Snap
×