Skip to content

Instantly share code, notes, and snippets.

@promto-c
Created March 9, 2024 21:16
Show Gist options
  • Select an option

  • Save promto-c/5a221e34dfff057c6e886b2db8d5fa06 to your computer and use it in GitHub Desktop.

Select an option

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.
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

promto-c commented Mar 9, 2024

Copy link
Copy Markdown
Author

download

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