Files
Artemis/fixed_aspect_ratio_label.py
alessandro90 8cb81dd225 Switch from filter panel to signal panel with double-click on
signal name. Also make minor style changes
2019-06-02 14:10:06 +02:00

39 lines
1.2 KiB
Python

from PyQt5.QtWidgets import QLabel
from PyQt5.QtCore import Qt
class FixedAspectRatioLabel(QLabel):
"""Subclass QLabel. A resizable label class."""
def __init__(self, parent=None):
"""Initialize the instance. Set the pixmap to None."""
super().__init__(parent)
self.pixmap = None
def set_default_stylesheet(self):
"""Set the initial stylesheet of the label."""
self.setStyleSheet("""border-width: 1px;
border-style: solid;
border-color: black;""")
def make_transparent(self):
"""Make the label transparent.
Remove text and border."""
self.setText('')
self.setStyleSheet("border-width: 0px;")
def apply_pixmap(self):
"""Apply a scaled pixmap without modifying the dimension of the original one."""
if self.pixmap:
self.setPixmap(
self.pixmap.scaled(
self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation
)
)
def rescale(self, size):
"""Rescale the widget and the displayed pixmap to the given size."""
self.resize(size)
self.apply_pixmap()