Skip to content

Commit

Permalink
Refactor QPushButton for region Tracker effect region selection, sinc…
Browse files Browse the repository at this point in the history
…e the old method did not work with Cosmic Dusk theme set. This new method is much cleaner.
  • Loading branch information
jonoomph committed Jun 24, 2024
1 parent d268644 commit b6eecd2
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/windows/process_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b6eecd2

Please sign in to comment.