
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - Drawing an Ellipse
An Ellipse is defined by two points, each called a focus. If any point on the Ellipse is taken, the sum of the distances to the focus points is constant. The size of the Ellipse is determined by the sum of these two distances. The sum of these distances is equal to the length of the major axis (the longest diameter of the ellipse). A circle is, in fact, a special case of an Ellipse.

Properties of ellipse −
- Center − It is a point where major and minor axis intersect.
- Major axis − Define the longest diameter of an ellipse.
- Minor axis − Define the shortest diameter of an ellipse.
Drawing a Ellipse in PyQt
Building an ellipse in PyQt needs various modules- QGraphics, QGraphicsView, QGraphicsEllipseItem, QApplication, QtWidgets, QBrush, QPainter, and, QPen. All these modules have convenience functions to operate the task of geometrical shape.
The shape of an ellipse can be formed using two methods- Ellipse() and drawEllipse(). Both these methods are used in different classes to build an ellipse.
Example 1
Following example illustrate the shape of ellipse using PyQt.
import sys from PyQt6.QtWidgets import QGraphicsScene, QGraphicsView, QGraphicsEllipseItem, QApplication from PyQt6.QtGui import QBrush, QColor class Ellipse(QGraphicsEllipseItem): def __init__(self, x, y, width, height, color): super(Ellipse, self).__init__(x, y, width, height) # Create a QBrush with the specified color for filling the ellipse brush = QBrush(QColor(color)) self.setBrush(brush) class MyScene(QGraphicsScene): def __init__(self): super(MyScene, self).__init__() # Create an ellipse at position (50, 50) with a width of 100, height of 60, and blue color # Specify the color in RGB value ellipse = Ellipse(40, 40, 400, 200, "#789287") # Add the ellipse to the scene self.addItem(ellipse) def main(): app = QApplication(sys.argv) # Create a QGraphicsView view = QGraphicsView() # Create an instance of MyScene scene = MyScene() # Set the scene for the view view.setScene(scene) # Show the view view.show() # Execute the application sys.exit(app.exec()) if __name__ == '__main__': main()
Output
The above code produces the following output −

Example 2
Following example illustrates the shape of ellipse using different code snippet. Here, QPainter, QBrush and QPen classes set the respective parameter to build the ellipse in color shape.
- QPen(Qt.GlobalColor.green, 5, Qt.PenStyle.SolidLine) − The QPen() method is used for drawline line. So, Qt class create the object for styling line.
- QBrush(Qt.GlobalColor.green, Qt.BrushStyle.SolidPattern) − The method QBrush() reference from QBrush class which provide color, texture, etc. for the shape.
from PyQt6 import QtWidgets from PyQt6.QtGui import QPainter, QBrush, QPen from PyQt6.QtCore import Qt class MyWidget(QtWidgets.QWidget): def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.RenderHint.Antialiasing) painter.setPen(QPen(Qt.GlobalColor.green, 5, Qt.PenStyle.SolidLine)) painter.setBrush(QBrush(Qt.GlobalColor.green, Qt.BrushStyle.SolidPattern)) painter.drawEllipse(40, 40, 400, 200) app = QtWidgets.QApplication([]) widget = MyWidget() widget.show() app.exec()
Output
The above code produces the following output −

Drawing a Cross Pattern Ellipse in PyQt
The cross pattern is a type of shape that is used in ellipse. Here, QBrush is the main class that fills the pattern of shape through the method Qpainter(). Then Qpainter has the built-in function drawEllipse() which draws the shape of an ellipse.
Example
Following example illustrate the code snippet of ellipse in cross-pattern style.
from PyQt6 import QtWidgets from PyQt6.QtGui import QPainter, QBrush, QPen from PyQt6.QtCore import Qt class MyWidget(QtWidgets.QWidget): def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.RenderHint.Antialiasing) painter.setPen(QPen(Qt.GlobalColor.red, 5, Qt.PenStyle.SolidLine)) painter.setBrush(QBrush(Qt.GlobalColor.gray, Qt.BrushStyle.CrossPattern)) painter.drawEllipse(40, 40, 400, 200) app = QtWidgets.QApplication([]) widget = MyWidget() widget.show() app.exec()
Output
The above code produces the following output −
