1#!/usr/local/bin/python3.8 2# 3# Electron Cash - lightweight Bitcoin client 4# Copyright (C) 2019 Axel Gembe <derago@gmail.com> 5# 6# Permission is hereby granted, free of charge, to any person 7# obtaining a copy of this software and associated documentation files 8# (the "Software"), to deal in the Software without restriction, 9# including without limitation the rights to use, copy, modify, merge, 10# publish, distribute, sublicense, and/or sell copies of the Software, 11# and to permit persons to whom the Software is furnished to do so, 12# subject to the following conditions: 13# 14# The above copyright notice and this permission notice shall be 15# included in all copies or substantial portions of the Software. 16# 17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24# SOFTWARE. 25 26from PyQt5.QtWidgets import QWidget 27from PyQt5.QtGui import QPixmap, QPainter, QPaintEvent 28 29 30class QrReaderVideoWidget(QWidget): 31 """ 32 Simple widget for drawing a pixmap 33 """ 34 35 USE_BILINEAR_FILTER = True 36 37 def __init__(self, parent: QWidget = None): 38 super().__init__(parent) 39 40 self.pixmap = None 41 42 def paintEvent(self, _event: QPaintEvent): 43 if not self.pixmap: 44 return 45 painter = QPainter(self) 46 if self.USE_BILINEAR_FILTER: 47 painter.setRenderHint(QPainter.SmoothPixmapTransform) 48 painter.drawPixmap(self.rect(), self.pixmap, self.pixmap.rect()) 49 50 def setPixmap(self, pixmap: QPixmap): 51 self.pixmap = pixmap 52 self.update() 53