butterfly_viewer.aux_layouts

Widget layouts for Butterfly Viewer.

Not intended as a script.

GridLayoutFloatingShadow extends QGridLayout by adding a dropshadow effect for added widgets.

 1#!/usr/bin/env python3
 2
 3"""Widget layouts for Butterfly Viewer.
 4
 5Not intended as a script.
 6
 7GridLayoutFloatingShadow extends QGridLayout by adding a dropshadow effect for added widgets.
 8"""
 9# SPDX-License-Identifier: GPL-3.0-or-later
10
11
12
13from PyQt5 import QtWidgets, QtCore, QtGui
14
15
16
17class GridLayoutFloatingShadow(QtWidgets.QGridLayout):
18    """Custom QGridLayout which adds a dropshadow effect to each added widget.
19
20    Instantiate without input. Add widgets only with addWidget(). Does not support addLayout().
21    
22    Dropshadow makes interface widgets more distinguishable as overlayed elements.
23    """
24
25    def __init__(self):
26        super().__init__()
27
28        margin = 20
29        self.setContentsMargins(margin, margin, margin, margin)
30        self.setSpacing(0)
31
32    def addWidget(self, widget, row_i, col_i, row_span=1, col_span=1, alignment=QtCore.Qt.AlignCenter):
33        """Override addWidget() to add widget to layout with dropshadow graphics effect.
34        
35        Args:
36            widget (QWidget or child class thereof): The widget to add to the layout.
37            row_i (int): The row location of the widget.
38            col_i (int): The column location of the widget.
39            row_span (int): The number of rows the widget spans.
40            col_span (int): The number of columns the widget spans.
41            alignment (AlignmentFlag): The alignment of the widget in the designated layout location.
42        """
43        shadow = QtWidgets.QGraphicsDropShadowEffect(blurRadius=16, color=QtGui.QColor(0, 0, 0, 255), xOffset=0, yOffset=0)
44        widget.setGraphicsEffect(shadow)
45        super().addWidget(widget, row_i, col_i, row_span, col_span, alignment)
class GridLayoutFloatingShadow(PyQt5.QtWidgets.QGridLayout):
18class GridLayoutFloatingShadow(QtWidgets.QGridLayout):
19    """Custom QGridLayout which adds a dropshadow effect to each added widget.
20
21    Instantiate without input. Add widgets only with addWidget(). Does not support addLayout().
22    
23    Dropshadow makes interface widgets more distinguishable as overlayed elements.
24    """
25
26    def __init__(self):
27        super().__init__()
28
29        margin = 20
30        self.setContentsMargins(margin, margin, margin, margin)
31        self.setSpacing(0)
32
33    def addWidget(self, widget, row_i, col_i, row_span=1, col_span=1, alignment=QtCore.Qt.AlignCenter):
34        """Override addWidget() to add widget to layout with dropshadow graphics effect.
35        
36        Args:
37            widget (QWidget or child class thereof): The widget to add to the layout.
38            row_i (int): The row location of the widget.
39            col_i (int): The column location of the widget.
40            row_span (int): The number of rows the widget spans.
41            col_span (int): The number of columns the widget spans.
42            alignment (AlignmentFlag): The alignment of the widget in the designated layout location.
43        """
44        shadow = QtWidgets.QGraphicsDropShadowEffect(blurRadius=16, color=QtGui.QColor(0, 0, 0, 255), xOffset=0, yOffset=0)
45        widget.setGraphicsEffect(shadow)
46        super().addWidget(widget, row_i, col_i, row_span, col_span, alignment)

Custom QGridLayout which adds a dropshadow effect to each added widget.

Instantiate without input. Add widgets only with addWidget(). Does not support addLayout().

Dropshadow makes interface widgets more distinguishable as overlayed elements.

def addWidget(self, widget, row_i, col_i, row_span=1, col_span=1, alignment=132):
33    def addWidget(self, widget, row_i, col_i, row_span=1, col_span=1, alignment=QtCore.Qt.AlignCenter):
34        """Override addWidget() to add widget to layout with dropshadow graphics effect.
35        
36        Args:
37            widget (QWidget or child class thereof): The widget to add to the layout.
38            row_i (int): The row location of the widget.
39            col_i (int): The column location of the widget.
40            row_span (int): The number of rows the widget spans.
41            col_span (int): The number of columns the widget spans.
42            alignment (AlignmentFlag): The alignment of the widget in the designated layout location.
43        """
44        shadow = QtWidgets.QGraphicsDropShadowEffect(blurRadius=16, color=QtGui.QColor(0, 0, 0, 255), xOffset=0, yOffset=0)
45        widget.setGraphicsEffect(shadow)
46        super().addWidget(widget, row_i, col_i, row_span, col_span, alignment)

Override addWidget() to add widget to layout with dropshadow graphics effect.

Arguments:
  • widget (QWidget or child class thereof): The widget to add to the layout.
  • row_i (int): The row location of the widget.
  • col_i (int): The column location of the widget.
  • row_span (int): The number of rows the widget spans.
  • col_span (int): The number of columns the widget spans.
  • alignment (AlignmentFlag): The alignment of the widget in the designated layout location.