PyQt5 Label - Accessing Vertical offset of shadow

PyQt5 Label - Accessing Vertical offset of shadow

In PyQt5, if you're referring to the shadow effect applied to a QLabel via QGraphicsDropShadowEffect, you can access the vertical offset using the yOffset() method of the shadow effect object.

Here's a brief example to illustrate this:

  1. Create a QLabel.
  2. Apply a QGraphicsDropShadowEffect to this label.
  3. Set a vertical (y) offset for the shadow.
  4. Access the vertical offset of the shadow.
import sys from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout from PyQt5.QtGui import QGraphicsDropShadowEffect app = QApplication(sys.argv) # Create a sample QWidget and QVBoxLayout window = QWidget() layout = QVBoxLayout() # Create a QLabel label = QLabel("Hello, PyQt5!") layout.addWidget(label) # Create and set a QGraphicsDropShadowEffect to the QLabel shadow_effect = QGraphicsDropShadowEffect() shadow_effect.setOffset(5, 10) # Setting x offset to 5 and y offset to 10 label.setGraphicsEffect(shadow_effect) # Accessing vertical offset of the shadow y_offset = shadow_effect.yOffset() print(f"Vertical offset of the shadow: {y_offset}") window.setLayout(layout) window.show() sys.exit(app.exec_()) 

In this example, when you run the script, you'll notice the shadow effect applied to the QLabel. The printed output should show:

Vertical offset of the shadow: 10.0 

This confirms that we've correctly accessed the vertical offset (y offset) of the shadow effect applied to the QLabel.


More Tags

tui set price docker-registry criteria dataformat heading input laravel timestamp-with-timezone

More Programming Guides

Other Guides

More Programming Examples