
- 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 - QGraphicsDropShadowEffect
Suppose we have a button or image on our computer screen and we want to make it more interactive.
Then we have a class like QGraphicsDropShadowEffect which helps to add a shadow behind the button or picture and make it stand out. We can modify the shadow color, blurred-effect, or make it any specific look.
The appearance of drop shadow effect uses the class QGraphicsDropShadowEffect. This class has same name of function which can used to render the source with a drop shadow.
We have three different uses of function that perform the task of drop shadow. Below is the list of following points −
- A color of drop shadow can be modified using the setColor() function.
- The drop shadow offset can be modified using the setOffset() function.
- We can apply blur radius to drop shadow which can be possible through the function setBlurRadius().
Note that the default color of drop shadow is a semi-transparent dark grey i.e. QColor(63, 63, 63, 180) and it is specified within the device coordinates.
Example 1
In this example, we illustrate the program of drop shadow button using various classes and methods in PyQt.
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QGraphicsDropShadowEffect from PyQt6.QtGui import QColor def create_drop_shadow(): # Create a button button = QPushButton("Click Here") # Create a QGraphicsDropShadowEffect shadow_effect = QGraphicsDropShadowEffect() # Set the shadow color shadow_effect.setColor(QColor(85, 85, 93, 180)) # Set the shadow offset (x, y) shadow_effect.setOffset(8, 8) # Set the blur radius shadow_effect.setBlurRadius(1) # Apply the effect to the button button.setGraphicsEffect(shadow_effect) return button if __name__ == "__main__": app = QApplication([]) # Create a main window main_window = QWidget() main_window.setGeometry(100, 100, 300, 200) main_window.setWindowTitle("QGraphicsDropShadowEffect") # Create a layout layout = QVBoxLayout(main_window) # Create a button with a drop shadow shadow_button = create_drop_shadow() # Add the button to the layout layout.addWidget(shadow_button) # Show the main window main_window.show() # Start the application event loop app.exec()
Output
The above code produces the following output −

Example 2
In this example, we display the graphical shape of a rectangle using the method QGraphicsRectItem() and the formation of shadow occurs using various functions of PyQt such as setColor(), offset(), setBlurRadius(), and setGraphicsEffect().
import sys from PyQt6.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QGraphicsRectItem, QGraphicsDropShadowEffect from PyQt6.QtGui import QColor, QPainter, QBrush def create_shadow_rect(): # Create a rectangle and adjust the position by specifying coordinates rect = QGraphicsRectItem(70, 70, 300, 200) # Create a QGraphicsDropShadowEffect shadow_effect = QGraphicsDropShadowEffect() # Set the color of shadow shadow_effect.setColor(QColor(89, 89, 78, 200)) # Set the offset(x, y) for shadow shadow_effect.setOffset(8, 8) # Set the blur radius shadow_effect.setBlurRadius(1) # Apply the effect to the rectangle rect.setGraphicsEffect(shadow_effect) return rect if __name__ == "__main__": app = QApplication(sys.argv) # Create a QGraphicsView and QGraphicsScene view = QGraphicsView() scene = QGraphicsScene() view.setScene(scene) # Create a shadowed rectangle shadow_rect = create_shadow_rect() scene.addItem(shadow_rect) # Show the view view.show() sys.exit(app.exec())
Output
The above code produces the following output −
