PyQt5 QDockWidget - Getting Graphics Effect Object

PyQt5 QDockWidget - Getting Graphics Effect Object

QDockWidget in PyQt5 provides a widget that can be docked inside a QMainWindow or floated as a top-level window on the desktop. If you've set a graphics effect to the QDockWidget (or any widget in general), you can retrieve the graphics effect using the graphicsEffect() method.

Here's a quick example to demonstrate how to set a graphics effect to a QDockWidget and how to get the graphics effect object:

import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QDockWidget, QLabel, QGraphicsDropShadowEffect from PyQt5.QtGui import QColor class App(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle('QDockWidget Graphics Effect') # Create a QDockWidget self.dock = QDockWidget("Sample Dock", self) label = QLabel("This is content inside dock", self.dock) self.dock.setWidget(label) # Set a drop shadow effect to the dock widget shadow_effect = QGraphicsDropShadowEffect(self.dock) shadow_effect.setBlurRadius(15) shadow_effect.setColor(QColor(0, 0, 0, 180)) shadow_effect.setOffset(5) self.dock.setGraphicsEffect(shadow_effect) self.addDockWidget(Qt.LeftDockWidgetArea, self.dock) self.setGeometry(100, 100, 600, 400) self.show() # Retrieve and print the graphics effect from the QDockWidget effect = self.dock.graphicsEffect() if effect: print("Graphics effect has been set!") else: print("No graphics effect set.") if __name__ == '__main__': app = QApplication(sys.argv) ex = App() sys.exit(app.exec_()) 

In the code above, we first set a drop shadow effect to the QDockWidget and then immediately retrieve it using the graphicsEffect() method to check if it has been set.


More Tags

client-certificates custom-object jsdoc jquery-events nvidia-titan svm radix-sort rs485 xcode-ui-testing jtable

More Programming Guides

Other Guides

More Programming Examples