Created
September 8, 2019 21:39
-
-
Save lmzach09/4164914e8dc4cbd90a3f7e5252f66b81 to your computer and use it in GitHub Desktop.
pyqt widget class for displaying an image. the image resizes to fill the space when the user resizes the desktop window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Widget for the single image that is currently on display | |
class DisplayImage(QWidget): | |
def __init__(self, parent=None): | |
QWidget.__init__(self) | |
self.parent = parent | |
self.pixmap = QPixmap() | |
self.label = QLabel(self) | |
self.assigned_img_full_path = '' | |
def update_display_image(self, path_to_image=''): | |
self.assigned_img_full_path = path_to_image | |
## render the display image when a thumbnail is selected | |
self.on_main_window_resize() | |
def on_main_window_resize(self, event=None): | |
main_window_size = self.parent.size() | |
main_window_height = main_window_size.height() | |
main_window_width = main_window_size.width() | |
display_image_max_height = main_window_height - 50 | |
display_image_max_width = main_window_width - 200 | |
self.pixmap = QPixmap(self.assigned_img_full_path) | |
self.pixmap = self.pixmap.scaled(\ | |
QSize(display_image_max_width, display_image_max_height), \ | |
Qt.KeepAspectRatio, \ | |
Qt.SmoothTransformation) | |
self.label.setPixmap(self.pixmap) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment