From b6eecd2ff7442a6b5ef708461475c350d78a5d02 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sun, 23 Jun 2024 22:38:58 -0500 Subject: [PATCH] Refactor QPushButton for region Tracker effect region selection, since the old method did not work with Cosmic Dusk theme set. This new method is much cleaner. --- src/windows/process_effect.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/windows/process_effect.py b/src/windows/process_effect.py index 8c18ddb4b..fd9a48eae 100644 --- a/src/windows/process_effect.py +++ b/src/windows/process_effect.py @@ -32,7 +32,7 @@ import webbrowser from PyQt5.QtCore import * -from PyQt5.QtGui import QBrush +from PyQt5.QtGui import QBrush, QPainter from PyQt5.QtWidgets import * import openshot # Python module for libopenshot (required video editing module installed separately) @@ -42,6 +42,25 @@ from classes.metrics import * +class RegionButton(QPushButton): + def __init__(self, parent=None): + super().__init__(parent) + self.qimage = None + + def setImage(self, qimage): + self.qimage = qimage + self.update() # Trigger a repaint + + def paintEvent(self, event): + super().paintEvent(event) + if self.qimage: + painter = QPainter(self) + resized_qimage = self.qimage.scaled(self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation) + painter.drawImage(0, 0, resized_qimage) + else: + super().paintEvent(event) # Draw the normal button + + class ProcessEffect(QDialog): """ Choose Profile Dialog """ progress = pyqtSignal(int) @@ -123,7 +142,7 @@ def __init__(self, clip_id, effect_class, effect_params): if param["type"] == "rect": # create QPushButton which opens up a display of the clip, with ability to select Rectangle - widget = QPushButton(_("Click to Select")) + widget = RegionButton(_("Click to Select")) widget.setMinimumHeight(80) widget.setToolTip(_(param["title"])) widget.clicked.connect(functools.partial(self.rect_select_clicked, widget, param)) @@ -292,14 +311,8 @@ def rect_select_clicked(self, widget, param): # Resize QImage to match button size resized_qimage = region_qimage.scaled(widget.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation) - # Draw Qimage onto QPushButton (to display region selection to user) - palette = widget.palette() - palette.setBrush(widget.backgroundRole(), QBrush(resized_qimage)) - widget.setFlat(True) - widget.setAutoFillBackground(True) - widget.setPalette(palette) - # Remove button text (so region QImage is more visible) + widget.setImage(resized_qimage) widget.setText("") # If data found, add to context