Skip to content

Commit

Permalink
fix: fix transparency mask for opaque overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Jul 15, 2022
1 parent db77d8d commit 542a6fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
28 changes: 21 additions & 7 deletions gridplayer/widgets/video_overlay.py
Expand Up @@ -95,14 +95,16 @@ def ui_setup(self): # noqa: WPS213
layout_main.setContentsMargins(0, 0, 0, 0)
layout_main.setStackingMode(QStackedLayout.StackAll)

control_widget = QWidget(self)
self.control_widget = QWidget(self)
self.control_widget.setMouseTracking(True)

self.border_widget = OverlayBorder(parent=self)
self.border_widget.hide()

layout_control = QVBoxLayout(control_widget)
layout_control = QVBoxLayout(self.control_widget)
layout_control.setContentsMargins(10, 10, 10, 10)

layout_main.addWidget(control_widget)
layout_main.addWidget(self.control_widget)
layout_main.addWidget(self.border_widget)

self.top_bar = QVBoxLayout()
Expand Down Expand Up @@ -334,14 +336,26 @@ def paintEvent(self, event):
self.move_to_parent()

if self.is_opaque:
mask = self.childrenRegion()
# 0 coord to keep children from sliding off
mask = mask.united(QRegion(QRect(0, 0, 1, 1)))
mask = QRegion(QRect(0, 0, 1, 1))

if self.border_widget.isVisible():
frame_width = 5
frame = QRegion(self.rect())
frame -= QRegion(
QRect(
frame_width,
frame_width,
self.width() - frame_width * 2,
self.height() - frame_width * 2,
)
)
mask = mask.united(frame)

mask = mask.united(self.control_widget.childrenRegion())

self.setMask(mask)

event.ignore()

def move_to_parent(self):
new_pos = self.parent().mapToGlobal(QPoint())

Expand Down
5 changes: 5 additions & 0 deletions gridplayer/widgets/video_overlay_elements.py
Expand Up @@ -480,6 +480,11 @@ def _get_y_within_bounds(self, y):


class OverlayBorder(OverlayWidget):
def __init__(self, **kwargs):
super().__init__(**kwargs)

self.setAttribute(Qt.WA_TransparentForMouseEvents)

def paintEvent(self, event) -> None:
painter = QPainter(self)

Expand Down

0 comments on commit 542a6fb

Please sign in to comment.