Created
March 9, 2024 21:16
-
-
Save promto-c/5a221e34dfff057c6e886b2db8d5fa06 to your computer and use it in GitHub Desktop.
A comprehensive demonstration of applying various graphical effects to widgets in PyQt5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PyQt5 import QtCore, QtGui, QtWidgets | |
| class EffectsDemo(QtWidgets.QWidget): | |
| def __init__(self): | |
| super().__init__() | |
| self.initUI() | |
| def initUI(self): | |
| self.setGeometry(300, 300, 240, 200) | |
| self.setWindowTitle('PyQt5 Button Graphics Effects Demo') | |
| # Layout | |
| layout = QtWidgets.QVBoxLayout() | |
| self.setLayout(layout) | |
| # Blur Effect Button | |
| blurButton = QtWidgets.QPushButton("Blur Effect") | |
| blurEffect = QtWidgets.QGraphicsBlurEffect() | |
| blurEffect.setBlurRadius(5) | |
| blurButton.setGraphicsEffect(blurEffect) | |
| layout.addWidget(blurButton) | |
| # Drop Shadow Effect Button | |
| shadowButton = QtWidgets.QPushButton("Shadow Effect") | |
| shadowEffect = QtWidgets.QGraphicsDropShadowEffect() | |
| shadowEffect.setBlurRadius(10) | |
| shadowEffect.setColor(QtGui.QColor('black')) | |
| shadowEffect.setOffset(5, 5) | |
| shadowButton.setGraphicsEffect(shadowEffect) | |
| layout.addWidget(shadowButton) | |
| # Colorize Effect Button | |
| colorizeButton = QtWidgets.QPushButton("Colorize Effect") | |
| colorizeEffect = QtWidgets.QGraphicsColorizeEffect() | |
| colorizeEffect.setColor(QtGui.QColor('red')) | |
| colorizeButton.setGraphicsEffect(colorizeEffect) | |
| layout.addWidget(colorizeButton) | |
| # Opacity Effect Button | |
| opacityButton = QtWidgets.QPushButton("Opacity Effect") | |
| opacityEffect = QtWidgets.QGraphicsOpacityEffect() | |
| opacityEffect.setOpacity(0.5) # 50% opacity | |
| opacityButton.setGraphicsEffect(opacityEffect) | |
| layout.addWidget(opacityButton) | |
| def main(): | |
| app = QtWidgets.QApplication([]) | |
| demo = EffectsDemo() | |
| demo.show() | |
| app.exec_() | |
| if __name__ == '__main__': | |
| main() |
promto-c
commented
Mar 9, 2024
Author

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment